Array Iterator

Docs

Allows creating owning iterators out of arrays. This is useful for fixed-size iterators. Try writing the following function:

compile_fail fn pair_iter(a: i32, b: i32) -> impl Iterator<Item=i32> { unimplemented!() }

This is hard to do because most iterators don't own the values they are iterating over. One ugly solution is:

``` fn pairiter(a: i32, b: i32) -> impl Iterator { Some(a).intoiter().chain(Some(b)) }

asserteq!(pairiter(1, 2).collect::>(), &[1, 2]); ```

This crate allows turning arrays into owning iterators, perfect for short, fixed-size iterators.

``` extern crate arrayiterator; use arrayiterator::ArrayIterator;

fn pair_iter(a: i32, b: i32) -> impl Iterator { ArrayIterator::new([a, b]) }

asserteq!(pairiter(1, 2).collect::>(), &[1, 2]); ```