std-method

slice::windows

Visit overlapping, fixed-width shared views one starting position at a time. If the slice is too short, no windows are returned; size zero panics. Expected stdout (not executed): 3 4 5 Common mistake: Expecting disjoint groups, or trying to take overlapping mutable windows.

Formal Syntax & Structure

rust syntaxrust
slice.windows(size)

Working Example

Example Snippetrust
fn main() {    let samples = [3, 6, 10, 15];    for pair in samples.windows(2) { println!("{}", pair[1] - pair[0]); }}
Rust Reference