Variables and Mutability
202307032103
Status: #idea
Tags: Rust
Variables and Mutability
- Declared using
letkeyword
Warning
let can only be used inside a function
- Immutable by default
mutkeyword is used to make variables mutable
let apples = 5; // Immutable
let mut bananas = 5; // Mutable
Shadowing
Let's you reuse the variable name
let mut guess = String::new();
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");
let guess: u32 = guess.trim().parse().expect("Please type a number!");