Values & References16 / 18
Up next

Shared xor mutable

fn main() {
    let mut s = String::from("hi");
    // any number of shared borrows can coexist
    let r1 = &s;
    let r2 = &s;
    println!("{r1} {r2}");
    // once those are done, a single mutable borrow is allowed
    let m = &mut s;
    m.push('!');
    println!("{m}");
}
What you're solving

many & readers, or one &mut writer