Variables
Rust provides type safety via static typing. Variable bindings are immutable by default:
fn main() {let x: i32 = 10;println!("x: {x}");// x = 20;// println!("x: {x}");}
Speaker Notes
- Due to type inference the
i32is optional. We will gradually show the types less and less as the course progresses. - Note that since
println!is a macro,xis not moved, even using the function like syntax ofprintln!("x: {}", x)