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();
These methods let you control how you read through a list of data. take grabs a specific number of items from the start, skip ignores a specific number from the start, and windows lets you look at small, moving groups of items at once. Think of it like reading a book: take is reading the first few pages, skip is jumping ahead to a later chapter, and windows is looking at a sliding view of the text to see how sentences connect.