Variables
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.
- Uncomment the
x = 20to demonstrate that variables are immutable by default. Add themutkeyword to allow changes. - The
i32here is the type of the variable. This must be known at compile time, but type inference (covered later) allows the programmer to omit it in many cases.
