[][src]Function tao_of_rust::ch05::share_mutable::immut_and_mut

pub fn immut_and_mut()

可变与不可变

Base usage: 绑定默认不可变

fn main() {
    let x = "hello".to_string();
    // cannot borrow immutable local variable `x` as mutable
    // x += " world";
}Run

Base usage: 结构体默认没有实现Copy

fn main() {
    let mut x = "hello".to_string();
    x += " world";
    assert_eq!("hello world", x);
}Run