From "Strings" chapter:
Rust has two main types of strings:
&str
andString
. Let’s talk about&str
first. These are called ‘string slices’. String literals are of the type&'static str
...
The problem is that a beginner who reads these lines can make a false conclusion that "string slice" and "string literal" mean the same thing, and string slices always has a static lifetime.
Comment from newcomer:
In fact, there is mention of the fact that the slices may has different lifetimes in the book. But from the point of view of a beginner there is no difference between "string slice" and "string literal", because these terms are used in the book as if they are synonymous. When I read these lines I always thought that these terms mean the same thing.
To be clear: a string literal is just a string slice that lives forever (because it's a pointer into the binary's rodata or whatever).
@gandro, yep, but looks like it is not obvious for newcomers. I think we should make these lines in the book more clear.
Yep, always a great thing to do! Just clarifying for whoever wants to fix this up.
Most helpful comment
@gandro, yep, but looks like it is not obvious for newcomers. I think we should make these lines in the book more clear.