RUST 0x01 数据类型
RUST 0x01 数据类型 1 变量与可变性 先上两段代码和一段错误信息: fn main() { let x = 5; println!("The value of x is: {}",x); x = 6; println!("The value of x is: {}",x); } error[E0384]: cannot assign twice to immutable variable `x` --> src/main.rs:4:5 | 2 | let x = 5; | - first assignment to `x` 3 | println!("The value of x is: {}", x); 4 | x = 6; | ^^^^^ cannot assign twice to immutable variable fn main() { let mut x = 5; println!("The value of x is: {}",x); x = 6; println!("The value of x is: {}",x); } let是函数式语言中的绑定(binding),而不是赋值(assignment) let →使前者绑定后者,且前者不能再被改变 mut →可变的(mutable) let mut →使前者绑定后者,但前者可以改变 变量与常量间的区别