Crate context_iterators
source ·Expand description
Iterators adaptors with associated read-only data.
Useful for naming the types of wrapped iterators by using function pointers or non-capturing closures.
use context_iterators::*;
type Closure = fn(usize, &usize) -> usize;
type MappedIterator = MapCtx<WithCtx<std::ops::Range<usize>, usize>, Closure>;
let iter: MappedIterator = (0..10)
.with_context(42)
.map_with_context(|item: usize, context: &usize| item + *context);
assert!(iter.eq(42..52));
The MappedIterator
type can be used in contexts where a concrete type is
needed, for example as an associated type for a trait.
trait Iterable {
type Iter: Iterator<Item = usize>;
}
struct MyIterable;
impl Iterable for MyIterable {
type Iter = MappedIterator;
}
Structs
- Apply a function to the context of an iterator.
- Filter the elements of an iterator.
- Map a function over an iterator, simultaneously filtering elements.
- Map a function over each element in the iterator.
- Wrapper around an iterator adding context data.
Traits
- Iterator carrying a context.
- Extended iterator trait to allow adding context data.