2 ms·
It’s not totally true right? &Vec would be the equivalent here, what you pointed to can only be obtained by doing vec.as_slice()
by baby 6y ago
It’s not totally true right? &Vec would be the equivalent here, what you pointed to can only be obtained by doing vec.as_slice()
- steveklabnik 6y agoThat is not correct, &Vec is fundamentally different. &str, &[T], and &Path are all "a pair of a pointer and a length," and String, Vec<T>, and PathBuf are all "a triple of a pointer, a length, and a capacity.". &Vec<T> is "a pointer to a triple of a pointer, a length, and a capacity."
- baby 6y agoI guess I’m a bit confused sometimes as what you get when you borrow. Sometimes I can borrow, sometimes I need to call .as_slice() or as_path or as_str
- steveklabnik 6y agoYeah, so thanks to “Deref coercion” a &Vec<T> will coerce into a &[T] in many places. That’s probably what you’re seeing.