context-iterators

Crates.iocontext-iterators
lib.rscontext-iterators
version0.2.0
sourcesrc
created_at2023-06-18 21:37:43.428166
updated_at2023-06-21 20:44:39.225896
descriptionIterators adaptors with associated read-only data.
homepage
repositoryhttps://github.com/aborgna/context_iterators
max_upload_size
id893648
size28,998
Agustín Borgna (ABorgna)

documentation

https://docs.rs/context-iterators/

README

context-iterators

build_status crates msrv

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;
}

Please read the API documentation here.

Recent Changes

See CHANGELOG for a list of changes. The minimum supported rust version will only change on major releases.

License

This project is dual-licensed under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0 or the MIT license http://opensource.org/licenses/MIT, at your option. This file may not be copied, modified, or distributed except according to those terms.

Commit count: 10

cargo fmt