← Rust Programming learning path
Rust Programming · Module 2 of 10

Variables, types and functions

Learn Rust syntax for values and functions.

📖 Key ideas

  1. Variables are immutable by default: let x = 5;
  2. Use let mut for mutable variables.
  3. Types: i32, u64, f64, bool, char, String, &str.
  4. Functions: fn add(a: i32, b: i32) -> i32 { a + b }.
  5. The last expression without ; is the return value.
💡 Real-life example: Immutable by default is like writing in pen: you must choose a pencil (mut) to make changes.
letDeclares a variable
mutMakes a variable mutable
i3232-bit signed integer
-> Function return type