Skip to content

Latest commit

 

History

History
24 lines (21 loc) · 598 Bytes

windows.md

File metadata and controls

24 lines (21 loc) · 598 Bytes

Windows

If you want to iterate over a slice in windows, you can use std::slice::Windows:

fn foo() {
    let slice = ['h', 'e', 'l', 'l', 'o', ' ', 't', 'h', 'e', 'r', 'e'];

    for window in slice.windows(2) {
      println!("{:?}", window);
      // prints ['h', 'e']
      //        ['e', 'l']
      //        ['l', 'l']
      //        ['l', 'o']
      //        ['o', ' ']
      //        [' ', 't']
      //        ['t', 'h']
      //        ['h', 'e']
      //        ['e', 'r']
      //        ['r', 'e']
    }
}