borrowing
Rust Mutable binding versus mutable referent
A mutable binding lets you replace the reference it stores; it does not change a shared reference into an exclusive one. Conversely, an unchanged binding holding &mut T can update its referent. Expected output (not executed): 5 8 3 Why: view changes its target; editor changes the value behind it. Common mistake: Thinking let mut r = &x allows *r = another_value.
Formal Syntax & Structure
rust syntaxrust
let mut view: &T = &first;Working Example
Example Snippetrust
fn main() { let first = 5; let second = 8; let mut view = &first; println!("{view}"); view = &second; println!("{view}"); let mut score = 1; let editor = &mut score; *editor += 2; println!("{score}");}