Change values with mut
Quick answer
A binding introduced with let mut may be reassigned. Use it when a value needs to change over time, such as a score or count. Keep bindings immutable when they do not need to change so that unintended assignments are caught.
Update a binding
In let mut count = 0;, mut permits later assignment to count. The expression on the right of an assignment is calculated before the new value is stored. The binding's type does not change just because it is mutable.
fn main() { let mut score = 5; score = score + 2; println!("Score: {score}");}Expected stdout (not executed):
Score: 7The old score is read, increased and replaced.
fn main() { let mut remaining = 8; remaining -= 3; remaining -= 2; println!("Remaining: {remaining}");}Expected stdout (not executed):
Remaining: 3-= subtracts and stores the result in the same binding.
Common mistake
mut does not permit assigning text to a binding inferred as an integer. It changes assignment permission, not the type.
Try it yourself
Start at 20, subtract 4 and add 3 using one mutable binding. Predict the result.
Static examples for Rust 1.85.0, edition 2024. Run them locally in a disposable project; ByteMind execution support and these outputs have not been verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Change values with mut — practice quiz
Choose one answer per question, then review the explanation.
What is the final value after `let mut left = 20; left -= 6; left -= 4;`?
Does `let mut n = 4i32; n = true;` compile?
What happens to n in `let mut n = 3; n = n * 2;`?