Trait itermore::IterWindows
source · pub trait IterWindows: Iterator {
fn windows<const N: usize>(self) -> Windows<Self, N> ⓘ
where
Self: Sized,
Self::Item: Clone,
{ ... }
}Expand description
An extension trait that provides the windows
method for iterators.
Provided Methods§
sourcefn windows<const N: usize>(self) -> Windows<Self, N> ⓘwhere
Self: Sized,
Self::Item: Clone,
fn windows<const N: usize>(self) -> Windows<Self, N> ⓘwhere
Self: Sized,
Self::Item: Clone,
Returns an iterator over all contiguous windows of length N.
The windows overlap. If the iterator is shorter than N, the iterator
returns no values.
This adapter clones the iterator elements so that they can be part of successive windows, this makes this it most suited for iterators of references and other values that are cheap to clone or copy.
Panics
If called with N = 0.
Examples
Basic usage:
use iterwindows::IterWindows;
let mut iter = "rust".chars().windows();
assert_eq!(iter.next(), Some(['r', 'u']));
assert_eq!(iter.next(), Some(['u', 's']));
assert_eq!(iter.next(), Some(['s', 't']));
assert_eq!(iter.next(), None);use iterwindows::IterWindows;
let seq: &[i32] = &[0, 1, 1, 2, 3, 5, 8, 13];
for [x, y, z] in seq.iter().copied().windows() {
assert_eq!(x + y, z);
}