[−][src]Macro ad_hoc_iter::iter
A bespoke iterator type with an exact size over elements.
This has an advantage over using simple inline slices (e.g [1,2,3]
) as they currently cannot implement IntoIterator
properly, and will always yield references.
This can be a hinderance when you want an ad-hoc iterator of non-Copy
items.
The iterator types created from this macro consume the values.
It has the advantage over vec![].into_iter()
as there are no heap allocations needed and size of the iterator is known at compile time.
Example
let sum: i32 = iter![1, 2].chain(3..=4).chain(iter![5, 6]).sum(); assert_eq!(sum, 21);
Functions
The iterators returned from this method have these 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