Crate iter_seq

Source
Expand description

Stateless, transformable, abstract sequences of values.

This crate provides a mechanism for working with abstract stateless sequences of arbitrary values. In contrast, standard iterators are stateful—that is, their state can be changed by calling next.

One significant limitation of the stateful model is its inability to encode compile-time invariants, which can lead to unnecessary overhead that the compiler often cannot reliably optimize away. This crate provides a “wrapper” around standard iterators that must be irreversibly converted into an iterator before its elements can be consumed.

§Example

use iter_seq::{Sequence, repeat};

let odd_squares = repeat(())
    .enumerate()
    .map(|(i, _)| i as u32)
    .map(|n| (n + 1) * (n + 1));

let arr: [u32; 128] = odd_squares.take_exact_s::<128>()
    .collect_array();

for (i, n) in arr.iter().enumerate() {
    assert_eq!((i as u32 + 1) * (i as u32 + 1), *n);
}

Re-exports§

pub use typenum;

Macros§

collect_array
Collects a sequence into an array in the most efficient way possible, ensuring that no unnecessary memory copies will occur.

Structs§

ArrayMutSliceSeq
ArraySeq
ArraySliceSeq
Const
Used to allow the usage of U in a generic context.
DynamicSize
Enumerate
A sequence that yields the current iteration index for every element.
Flatten
InfiniteSize
IterSeq
A sequence created from an iterator.
Map
A sequence that transforms every element of the original sequence using f
Repeat
StaticSize
TakeExactSTn

Enums§

SizeKind

Traits§

ArrayExt
IntoIteratorExt
IsDynamic
IsEqual
IsFinite
IsGreaterOrEqual
IsGreaterThan
IsInfinite
IsLessOrEqual
IsLessThan
LowerBound
A Sequence that is guaranteed to yield at least N elements, but could yield more.
Sequence
Represents a stateless abstract sequence of values.
Size
ToUInt
Unsigned
The marker trait for compile time unsigned integers.
UpperBound
A Sequence that is guaranteed to yield at most N elements, but could yield less.
WithLowerBound
WithUpperBound

Functions§

from_fn
repeat

Type Aliases§

FlatMap
FromFn
TakeExactS
U