Ad-hoc exact size owning iterator macro for Rust.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Avril 6af0d8a470
fix allow trailing comma in
2 years ago
src fix allow trailing comma in 2 years ago
.gitignore initial commit 3 years ago
Cargo.toml fix allow trailing comma in 2 years ago added README 3 years ago

Ad-hoc owning iterator types

This crate defines the macro iter! which produces ad-hoc iterator types that own their values and have compile-time known exact sizes.


This macro can be used exactly like vec!, except it produces an impl Iterator that does not allocate. This impl Iterator yields the values directly, not references to the values.

This can be useful for when you want a ad-hoc iterator of a non-copy type, as sized slices and arrays currently do not implement IntoIterator in a way that moves their values, instead they yield references, causing the need for cloning.

The iter! macro's iterator types move their values on calls to next() instead of returning references, and drop the non-consumed values when the iterator is dropped itself.


Concatenating a 'slice' of String without cloning.

let whole: String = iter![String::from("Hell"),
			  String::from("o "),
assert_eq!("Hello world!", &whole[..]);


The iterator types also have a few associated functions.

The length of the whole iterator

pub const fn len(&self) -> usize

The rest of the iterator that has not been consumed.

pub fn rest(&self) -> &[T]

The whole array.

All values that have not been consumed are initialised, values that have been consumed are uninitialised.

pub fn array(&self) -> &[MaybeUninit<T>; Self::LEN]

How many items have since been consumed.

pub const fn consumed(&self) -> usize