pub trait IterArrayWindows: Iterator {
    // Provided method
    fn array_windows<const N: usize>(self) -> ArrayWindows<Self, N> 
       where Self: Sized,
             Self::Item: Clone { ... }
}
Available on crate feature array_windows only.
Expand description

An extension trait that provides the array_windows method for iterators.

Provided Methods§

source

fn array_windows<const N: usize>(self) -> ArrayWindows<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 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::IterArrayWindows;

let mut iter = "rust".chars().array_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 itermore::IterArrayWindows;

let seq: &[i32] = &[0, 1, 1, 2, 3, 5, 8, 13];
for [x, y, z] in seq.iter().copied().array_windows() {
    assert_eq!(x + y, z);
}

Implementors§

source§

impl<I> IterArrayWindows for I
where I: Iterator + ?Sized,