pub trait IterCircularArrayWindows: Iterator {
    // Provided method
    fn circular_array_windows<const N: usize>(
        self
    ) -> CircularArrayWindows<Self, N> 
       where Self: Sized + Clone + ExactSizeIterator,
             Self::Item: Clone { ... }
}
Available on crate feature circular_array_windows only.

Provided Methods§

source

fn circular_array_windows<const N: usize>(self) -> CircularArrayWindows<Self, N>
where Self: Sized + Clone + ExactSizeIterator, Self::Item: Clone,

Returns an iterator over all contiguous windows of length N wrapping back to the first elements when the window would otherwise exceed the length of the iterator.

This adaptor 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 itermore::IterCircularArrayWindows;

let mut iter = (1..5).into_iter().circular_array_windows();
assert_eq!(iter.next(), Some([1, 2]));
assert_eq!(iter.next(), Some([2, 3]));
assert_eq!(iter.next(), Some([3, 4]));
assert_eq!(iter.next(), Some([4, 1]));
assert_eq!(iter.next(), None);

If the window is smaller than the iterator length, then the iterator will wrap around multiple times.

use itermore::IterCircularArrayWindows;

let mut iter = (1..2).into_iter().circular_array_windows::<3>();
assert_eq!(iter.next(), Some([1, 1, 1]));

Implementors§