rust calls the action of creating a reference borrowing.
• At any given time, you can have either one mutable reference or any number of immutable references so rust can prevent data races at compile time.
we can use curly brackets to create a new scope, allowing for multiple mutable references, just not simultaneous ones:
let mut s = String::from("hello");
{
let r1 = &mut s;
}
// r1 goes out of scope here, so we can make a new reference with no problems.
let r2 = &mut s;
a reference’s scope starts from where it is introduced and continues through the last time that reference is used.
let mut s = String::from("hello");
let r1 = &s; // no problem
let r2 = &s; // no problem
println!("{r1} and {r2}");
// Variables r1 and r2 will not be used after this point.
let r3 = &mut s; // no problem
println!("{r3}");