#iterator #array #owning #std #deprecated

deprecated array_iterator

Owning iterators based on arrays

11 releases (5 stable)

1.8.0 Jul 5, 2021
1.5.0 May 1, 2021
1.4.0 Mar 25, 2021
1.3.0 Jan 11, 2021
0.1.0 Mar 15, 2019

#11 in #owning

Download history 8/week @ 2024-02-14 39/week @ 2024-02-21 19/week @ 2024-02-28 17/week @ 2024-03-06 14/week @ 2024-03-13 8/week @ 2024-03-20 39/week @ 2024-03-27 28/week @ 2024-04-03

97 downloads per month
Used in 2 crates

Apache-2.0

13KB
209 lines

Array Iterator (DEPRECATED)

std::array::IntoIter is now stable, use that instead!. I will be maintaining this crate for the foreseeable future but plan on pushing an update that produces deprecation warnings in the future.

Migrating Off

You can easily migrate off using comby.

comby \
	'array_iterator::ArrayIterator::new(:[args])' \
	'std::array::IntoIter::new(:[args])' \
	.rs -in-place

You can also remove the dependency. This can be done automatically using cargo-edit.

cargo rm array_iterator
cargo check

Docs

Docs


lib.rs:

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]);

No runtime deps