-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
String guide: make distinction between str
and &str
#21035
Comments
Note: |
The error messages can be quite unfriendly for new users. I recently saw someone attempt: struct S {
s: str
}
fn main() {
let hi = "Hi";
let s = S { s: *hi };
println!("Hello errors!");
} The error:
Doesn't mean much to a new user.
What does that mean to users? Is there a valid reason to ever use The std::str doc says
So it's not a valid type? But the error message you gave me said "for the type |
Today, this is the string chapter of the book. |
The string guide distinguishes between
String
and&str
but makes no mention of a third type people will come across:str
.&str
is defined as the type which you refer to? Perhaps definestr
as the type and mention that in most cases it must be borrowed...This honestly threw me the first time I saw it. I thought, "what is
str
...there's only&str
andString
...".Problematic case:
Error:
The text was updated successfully, but these errors were encountered: