Crate array_iterator[−][src]
Expand description
This create is now deprecated as this functionality has been implemented in std since 1.15.0. Please use std::array::IntoIter::new
instead.
fn pair_iter(a: i32, b: i32) -> impl Iterator<Item=i32> { std::array::IntoIter::new([a, b]) }
This crate will continue to receive bug and security fixes for the foreseeable future. No new features, docs or any other changes will be added.
Previous docs are below:
Allows creating owning iterators out of arrays. This is useful for fixed-size iterators. Try writing the following function:
ⓘ
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 pair_iter(a: i32, b: i32) -> impl Iterator<Item=i32> { Some(a).into_iter().chain(Some(b)) } assert_eq!(pair_iter(1, 2).collect::<Vec<_>>(), &[1, 2]);
This crate allows turning arrays into owning iterators, perfect for short, fixed-size iterators.
use array_iterator::ArrayIterator; fn pair_iter(a: i32, b: i32) -> impl Iterator<Item=i32> { ArrayIterator::new([a, b]) } assert_eq!(pair_iter(1, 2).collect::<Vec<_>>(), &[1, 2]);
Structs
ArrayIteratorDeprecated
Traits
ArrayDeprecated
Trait for array-like types that can be used as an iterator.