mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-06-30 00:08:45 +00:00
docs: clarify variables5 mutability
This commit is contained in:
parent
4bab596677
commit
364015c14e
@ -3,6 +3,7 @@
|
|||||||
In Rust, variables are immutable by default.
|
In Rust, variables are immutable by default.
|
||||||
When a variable is immutable, once a value is bound to a name, you can't change that value.
|
When a variable is immutable, once a value is bound to a name, you can't change that value.
|
||||||
You can make them mutable by adding `mut` in front of the variable name.
|
You can make them mutable by adding `mut` in front of the variable name.
|
||||||
|
`variables5` is about that `mut` keyword, not shadowing.
|
||||||
|
|
||||||
## Further information
|
## Further information
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,8 @@ fn main() {
|
|||||||
let number = "T-H-R-E-E"; // Don't change this line
|
let number = "T-H-R-E-E"; // Don't change this line
|
||||||
println!("Spell a number: {number}");
|
println!("Spell a number: {number}");
|
||||||
|
|
||||||
// TODO: Fix the compiler error by changing the line below without renaming the variable.
|
// TODO: Fix the compiler error by making `number` mutable.
|
||||||
|
// This exercise is about mutability, not shadowing.
|
||||||
number = 3;
|
number = 3;
|
||||||
println!("Number plus two is: {}", number + 2);
|
println!("Number plus two is: {}", number + 2);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user