Skip to content

Strings chapter: &String doesn't actually coerce to &str #21850

@FreeFull

Description

@FreeFull

"Strings will coerece into &str with an &:

fn takes_slice(slice: &str) {
    println!("Got: {}", slice);
}

fn main() {
    let s = "Hello".to_string();
    takes_slice(&s);
}

"
This example should have &*s rather than &s, and the line above it should be reworded, since this isn't a coercion. (Note coerce is misspelled as coerece)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions