Variables

Rust provides type safety via static typing. Variable bindings are immutable by default:

  1. fn main() {
  2. let x: i32 = 10;
  3. println!("x: {x}");
  4. // x = 20;
  5. // println!("x: {x}");
  6. }
  • Due to type inference the i32 is optional. We will gradually show the types less and less as the course progresses.
  • Note that since println! is a macro, x is not moved, even using the function like syntax of println!("x: {}", x)