let / let mut
Variable definition; immutable by default.
Syntax
let name = value; · let mut name = value;
Description
Variables defined with let are immutable by default. To make them mutable, let mut is required — Rust's safety philosophy.
Example
Loading editor…
Expected output
5 20
When to use?
Storing all kinds of data.
Common mistakes
- ⚠️ Modifying without mut is an ERROR: let x = 5; x = 6; → fails to compile.