#iterator #context #data #associated #read-only #adaptor #pointers

context-iterators

Iterators adaptors with associated read-only data

3 unstable releases

0.2.0 Jun 21, 2023
0.1.1 Jun 19, 2023
0.1.0 Jun 18, 2023

#1934 in Rust patterns

Download history 1634/week @ 2024-07-19 1554/week @ 2024-07-26 727/week @ 2024-08-02 1214/week @ 2024-08-09 1277/week @ 2024-08-16 1245/week @ 2024-08-23 2395/week @ 2024-08-30 1371/week @ 2024-09-06 691/week @ 2024-09-13 694/week @ 2024-09-20 896/week @ 2024-09-27 1137/week @ 2024-10-04 1582/week @ 2024-10-11 1423/week @ 2024-10-18 688/week @ 2024-10-25 1044/week @ 2024-11-01

5,004 downloads per month
Used in 11 crates (3 directly)

MIT/Apache

15KB
351 lines

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.

No runtime deps