Rust enforces a rule allowing only one mutable reference to a specific data location at any given time.
You can have only one mutable reference to a particular piece of data at a time. This rule prevents data races by ensuring that no two parts of your code can modify the same data simultaneously.
fn main() {
let mut s = String::from("hello");
let r1 = &mut s;
// let r2 = &mut s; // This would cause a compile error
println!("{r1}");
}
Rust allows only one person to edit a specific document at a time to prevent conflicting changes. If you try to create a second mutable reference while the first one is still active, the compiler stops you immediately. This ensures your data remains consistent and safe from accidental overwrites.