2 ms·
I spent a whole day struggling with a bug because I equated &[T] with *T and thought you could cast one to the other (for interop with C++ code). It took me too
by Paul-ish 9y ago
I spent a whole day struggling with a bug because I equated &[T] with *T and thought you could cast one to the other (for interop with C++ code). It took me too long to figure out that &[T] is two words long, but now its obvious. I'm not sure where I thought the "length" part was being stored.
- FreeFull 9y agoFor reference, the proper way to get a *const T from a &[T] is the .as_ptr() method. The way &[T] (and any other type not marked with #[repr(C)]) is laid out is implementation-defined, so accessing its internals isn't recommended.