How to Use take, skip, and windows in Rust

Use take, skip, and windows to slice, ignore, or view overlapping sections of Rust iterators.

Use take to consume the first N items, skip to ignore the first N items, and windows to create an iterator of overlapping slices from a collection.

let numbers = vec![1, 2, 3, 4, 5];

// Take first 2 items: [1, 2]
let taken: Vec<_> = numbers.iter().take(2).copied().collect();

// Skip first 2 items: [3, 4, 5]
let skipped: Vec<_> = numbers.iter().skip(2).copied().collect();

// Windows of size 3: [[1,2,3], [2,3,4], [3,4,5]]
let windows: Vec<_> = numbers.windows(3).collect();