变量
Rust provides type safety via static typing. Variable bindings are made with let:
1. fn main() {
2. let x: i32 = 10;
3. println!("x: {x}");
4. // x = 20;
5. // println!("x: {x}");
6. }
This slide should take about 5 minutes.
- 取消备注
x = 20,以证明变量默认是不可变的。添加mut关键字以允许进行更改。 - 这里的
i32是变量的类型。编译时必须已知类型,但在很多情况下,由于具有类型推理功能(稍后介绍),程序员可以忽略这一点。
