Skip to content

Listing 4-6 is unclear #4707

@qucchia

Description

@qucchia

The purpose of listing 4-6 is to explain how references aren't necessarily mutable:

fn main() {
    let s = String::from("hello");

    change(&s);
}

fn change(some_string: &String) {
    some_string.push_str(", world");
}

However, the point may be unclear as s is declared as immutable anyway, so the user who has read the previous sections wouldn't expect this to compile in the first place. The second line should be changed to

    let mut s = String::from("hello");

in order to make the point better.

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