Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Mutable iterator

  • iter_mut
fn main() {
    let mut numbers = [2, 3, 4];
    println!("{numbers:?}");

    for num in numbers.iter_mut() {
        *num += 1;
    }

    println!("{numbers:?}");
}
[2, 3, 4]
[3, 4, 5]