Values & References13 / 18
Up next

Pass a &mut onward

fn increment(n: &mut i32) {
    *n += 1;
}

// forwarding a &mut reborrows it for the inner call
fn bump_twice(n: &mut i32) {
    increment(n);
    increment(n);
}

fn main() {
    let mut x = 0;
    bump_twice(&mut x);
    println!("{x}");
}
What you're solving

reborrow when forwarding a mutable ref