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::*;
use std::ops::Range;
type MappedIterator = MapCtx<WithCtx<Range<u16>, u16>, usize>;
let iter: MappedIterator = (0..10)
.with_context(42)
.map_with_context(|item: u16, context: &u16| (item + *context) as usize);
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§
- CtxMap
- Apply a function to the context of an iterator.
- Filter
Ctx - Filter the elements of an iterator.
- Filter
MapCtx - Map a function over the elements of an iterator, simultaneously filtering elements.
- MapCtx
- Map a function over each element in the iterator.
- WithCtx
- Wrapper around an iterator adding context data.
Traits§
- Context
Iterator - Iterator carrying a context.
- Into
Context Iterator - Extended iterator trait to allow adding context data.
Type Aliases§
- Filter
MapWith Ctx - Map a function over the elements of an iterator, simultaneously filtering elements. Passes a context to each function call.
- Filter
With Ctx - Filter the elements of an iterator, passing a context to each function call.
- MapWith
Ctx - Map a function over each element in an iterator, passing a context to each function call.