Fundamentals27 / 42
Up next

Mutable borrow (&mut)

fn add_bang(s: &mut String) {
    // mutate through the borrow
    s.push('!');
}

fn main() {
    let mut s = String::from("hi");
    add_bang(&mut s);
    println!("{s}");
}
What you're solving

change a value through a reference