Crates.io | ad-hoc-iter |
lib.rs | ad-hoc-iter |
version | 0.2.3 |
source | src |
created_at | 2020-11-09 15:53:51.955847 |
updated_at | 2020-12-30 12:57:37.991358 |
description | Ad-hoc exact size owning iterator macro and other optional utils |
homepage | |
repository | https://git.flanchan.moe/flanchan/ad-hoc-iter |
max_upload_size | |
id | 310359 |
size | 14,588 |
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 "),
String::from("world"),
String::from("!")]
.collect();
assert_eq!("Hello world!", &whole[..]);
The iterator types also have a few associated functions.
pub const fn len(&self) -> usize
pub fn rest(&self) -> &[T]
All values that have not been consumed are initialised, values that have been consumed are uninitialised.
pub fn array(&self) -> &[MaybeUninit<T>; Self::LEN]
pub const fn consumed(&self) -> usize
MIT