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

Ch04-03 Slices - String is coerced to &str #2298

Closed
GeeF opened this issue Apr 7, 2020 · 1 comment
Closed

Ch04-03 Slices - String is coerced to &str #2298

GeeF opened this issue Apr 7, 2020 · 1 comment

Comments

@GeeF
Copy link

GeeF commented Apr 7, 2020

Regarding listing-04-09: &String is actually coerced to &str as of rust-lang/rust#21351.
Should this be mentioned at this point in the book?

fn first_word(s: &str) -> &str {
..

fn main() {
    let my_string = String::from("hello world");
    // first_word works on slices of `String`s
    let word = first_word(&my_string[..]);
    let word = first_word(&my_string); // this is also valid now
    ..
@steveklabnik
Copy link
Member

Thanks for this! You're right that we could also mention this here, but there's already a lot going on, and understanding this requires knowledge we learn a lot later. I think i'd like to keep it as-is for now. Thank you!

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