iter_enumeration 0.1.0

Unifies Iterators over Same Type
Documentation
  • Coverage
  • 1.96%
    1 out of 51 items documented1 out of 31 items with examples
  • Size
  • Source code size: 8.29 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 6.31 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Vollkornaffe/iter_enumeration
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Vollkornaffe

iter_enumeration

This crate provides utility to unify Iterators over the same type.

Dealing with Iterator types originating from different parts of the code, such as separate branches of a match, can be a bit cumbersome. A similar problem arises with an iterator over iterators.

Alternative solutions to this problem: One can collect the iterator, do something with Box<dyn Iterator>, or redesign altogether.

However, this crate allows you to do this:

Example

use iter_enumeration::{IterEnum2, IntoIterEnum2};

// start with any iterator
let it = 0..10;

// have some branching code
let it = if true {
    // and call the trait extension method
    it.map(|i| i * i).iter_enum_2a()
} else {
    // or use the enum directly
    IterEnum2::B(it.filter(|i| i % 2 == 0))
};

// continue with the unified iterator enum type
let it = it.inspect(|i| println!("{i}"));

// or have more branches, up to 6, currently
use iter_enumeration::IntoIterEnum3;
let it = match 42 {
    0 => it.iter_enum_3a(),
    1 => it.take(10).iter_enum_3b(),
    _ => it.skip(10).iter_enum_3c(),
};

Note that there is also iter-enum, which provides a similar solution but differs from what I want: You either have to define the enum yourself or use auto_enum, which uses proc-macros.