t_wの輪郭

Feedlyでフォローするボタン
ふへん
不変DB「Rustでは、変数は標準で不変(immutable)」不変変数Rustの文字列リテラルは不変不変変数の参照は不変イベント不変参照
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
    */
}