How to Use the chunks and windows Methods on Slices

Use chunks(n) for fixed-size groups and windows(n) for overlapping sliding views on Rust slices.

Use chunks(n) to split a slice into fixed-size sub-slices and windows(n) to create an iterator of overlapping sub-slices of size n.

let data = [1, 2, 3, 4, 5];

// Fixed-size chunks: [1, 2], [3, 4], [5]
for chunk in data.chunks(2) {
    println!("{:?}", chunk);
}

// Overlapping windows: [1, 2, 3], [2, 3, 4], [3, 4, 5]
for window in data.windows(3) {
    println!("{:?}", window);
}