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.
The purpose of listing 4-6 is to explain how references aren't necessarily mutable:
However, the point may be unclear as
sis 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 toin order to make the point better.