pub trait ArrayIterator<const N: usize>: Sized {
type Item;
// Required method
unsafe fn next(&mut self) -> Self::Item;
// Provided methods
fn map<U, F: Fn(Self::Item) -> U>(self, f: F) -> Map<Self, F> { ... }
fn zip<B: IntoArrayIterator<N>>(self, b: B) -> Zip<Self, B::ArrayIter> { ... }
fn collect(self) -> [Self::Item; N] { ... }
fn unzip<A, B>(self) -> ([A; N], [B; N])
where Self: ArrayIterator<N, Item = (A, B)> { ... }
}Expand description
Similar to Iterator, ArrayIterator is an iterator over constant sized arrays
use array_iter_tools::{ArrayIterator, IntoArrayIterator};
let a = [1, 2, 3, 4];
let b = [5, 6, 7, 8];
let c = a.into_array_iter().zip(b).map(|(a, b)| a + b).collect();
assert_eq!(c, [6, 8, 10, 12]);Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn map<U, F: Fn(Self::Item) -> U>(self, f: F) -> Map<Self, F>
fn map<U, F: Fn(Self::Item) -> U>(self, f: F) -> Map<Self, F>
Lazily mutate the contents of an array
Sourcefn zip<B: IntoArrayIterator<N>>(self, b: B) -> Zip<Self, B::ArrayIter>
fn zip<B: IntoArrayIterator<N>>(self, b: B) -> Zip<Self, B::ArrayIter>
Lazily combine two ArrayIterators into an new one
Sourcefn collect(self) -> [Self::Item; N]
fn collect(self) -> [Self::Item; N]
Collect the contents of this ArrayIterator into an array
This is very similar to build_array but ignores
the case that any drop handlers need to be called
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.