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

Skip the first N elements of an iterator

  • skip
fn main() {
    let skipped = (0..10).skip(5).collect::<Vec<_>>();
    let range = (5..10).collect::<Vec<_>>();
    assert_eq!(skipped, range);
    println!("{:?}", skipped);

    // If we exhaust the iterator while skipping, that's fine. We get an empty iterator.
    let numbers = (0..5).skip(10).collect::<Vec<_>>();
    println!("{:?}", numbers);
}
[5, 6, 7, 8, 9]
[]