pub struct String {
vec: Vec<u8>,
}
Then why is there a special syntax (&str
) for a slice of a Vec<u8>
? In Chapter 3 of "Programming Rust" by Jim Blandy & Jason Orendorff it says,
&str
is very much like&[T]
: a fat pointer to some data.String
is analogous toVec<T>
Following that statement there is a chart which shows all the ways they're similar, but there isn't any mention of a single method that they're different. Is a &str;
just a &[T]
?
Likewise in the answer to, What are the differences between Rust's String
and str
? it says
This is identical to the relationship between a vector
Vec<T>
and a slice&[T]
, and is similar to the relationship between by-valueT
and by-reference&T
for general types.
That question focuses on the difference between String
and &str
. Knowing that a String
really is a vector of u8
, I'm more interested in &str
, which I can't even find the source to. Why does this primitive even exist when we have a primitive (implemented as a fat pointer) for regular vector slices?