Variability of variables#
let#
In Rust, you declare variables using the let keyword as follows.
fn main() {
let apple = 10;
}However, since let is fundamentally immutable, trying to change the value of apple as shown below will result in an error.
fn main() {
let apple = 10;
apple = 20;
}error[E0384]: cannot assign twice to immutable variable `apple`let mut#
To modify a value, you need to use the let mut keyword as follows.
Here, mut stands for mutable.