不変変数の参照は不変
2022/2/17 22:32:00
fn main() {
let s = String::from("hello");
change(&s);
}
fn change(some_string: &String) {
some_string.push_str(", world");
/*
error[E0596]: cannot borrow `*some_string` as mutable, as it is behind a `&` reference
--> src\main.rs:7:5
|
6 | fn change(some_string: &String) {
| ------- help: consider changing this to be a mutable reference: `&mut String`
7 | some_string.push_str(", world");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `some_string` is a `&` reference, so the data it refers to cannot be borrowed as mutable
*/
}