Basics
Variables
Mutability and Shadowing
Rust names are immutable by default. mut allows reassignment, and a second let shadows a name with a new binding.
Program
Play the program to watch count change by reassignment and then by shadowing.
variables.rs
fn main() {
let mut count = 1;
count = count + 2;
let count = count * 10;
println!("{count}");
}
mut
`let mut` allows a binding to be reassigned.
reassignment
`count = count + 2` updates the existing mutable value.
shadowing
A new `let count` creates a fresh binding that hides the old one.