Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: Unclear difference between "string slices" and "string literals" for newcomers #29823

Closed
defuz opened this issue Nov 14, 2015 · 3 comments

Comments

@defuz
Copy link
Contributor

defuz commented Nov 14, 2015

From "Strings" chapter:

Rust has two main types of strings: &str and String. 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.

@Gankra
Copy link
Contributor

Gankra commented Nov 14, 2015

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).

@Gankra Gankra added the A-book label Nov 14, 2015
@defuz
Copy link
Contributor Author

defuz commented Nov 14, 2015

@gandro, yep, but looks like it is not obvious for newcomers. I think we should make these lines in the book more clear.

@Gankra
Copy link
Contributor

Gankra commented Nov 14, 2015

Yep, always a great thing to do! Just clarifying for whoever wants to fix this up.

JanLikar added a commit to JanLikar/rust that referenced this issue Nov 15, 2015
Fix rust-lang#29823 by further explaining `&str` and pointing out the
difference between `&str` and `&'static str`.
bors added a commit that referenced this issue Nov 15, 2015
Fix #29823 by further explaining `&str` and pointing out the
difference between `&str` and `&'static str`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants