ArrayIterator

Trait ArrayIterator 

Source
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§

Source

type Item

Item returned by this ArrayIterator

Required Methods§

Source

unsafe fn next(&mut self) -> Self::Item

Get the next item out of this ArrayIterator

Safety: This function is used internally by collect and unzip Calling next and then calling one of those two functions is undefined behaviour.

Calling next > N times is also undefined behaviour.

Provided Methods§

Source

fn map<U, F: Fn(Self::Item) -> U>(self, f: F) -> Map<Self, F>

Lazily mutate the contents of an array

Source

fn zip<B: IntoArrayIterator<N>>(self, b: B) -> Zip<Self, B::ArrayIter>

Lazily combine two ArrayIterators into an new one

Source

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

Source

fn unzip<A, B>(self) -> ([A; N], [B; N])
where Self: ArrayIterator<N, Item = (A, B)>,

Separate and collect the contents of the ArrayIterator into two arrays

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.

Implementors§

Source§

impl<'a, T, const N: usize> ArrayIterator<N> for array_iter_tools::mut_ref::ArrayIter<'a, T, N>

Source§

impl<'a, T, const N: usize> ArrayIterator<N> for array_iter_tools::reference::ArrayIter<'a, T, N>

Source§

impl<A, B, const N: usize> ArrayIterator<N> for Zip<A, B>
where A: ArrayIterator<N>, B: ArrayIterator<N>,

Source§

type Item = (<A as ArrayIterator<N>>::Item, <B as ArrayIterator<N>>::Item)

Source§

impl<T, const N: usize> ArrayIterator<N> for array_iter_tools::array::ArrayIter<T, N>

Source§

type Item = T

Source§

impl<U, A, F, const N: usize> ArrayIterator<N> for Map<A, F>
where A: ArrayIterator<N>, F: Fn(A::Item) -> U,

Source§

type Item = U