-
-
Notifications
You must be signed in to change notification settings - Fork 82
Open
Labels
trackingTracking issue for an epicTracking issue for an epic
Milestone
Description
Similar to Rust, we want to use opt-in mutability; i.e. by default all variables are immutable. If you want to edit a variable, you need to declare it as with the mut keyword. E.g. this example should result in a compile error:
let foo = 5;
if condition() {
foo += 1; // error: `foo` is not mutable
}This code would be correct:
let mut foo = 5;
if condition() {
foo += 1;
}This construct extends to function arguments. E.g. if you want to make a function argument mutable:
fn foo(mut arg: u32) {
arg += 1;
// ...
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
trackingTracking issue for an epicTracking issue for an epic