#iterator #derive #enum

macro iterator-enum

#[derive(Iterator, DoubleEndedIterator, ExactSizeIterator, Extend)] for enums

6 releases

✓ Uses Rust 2018 edition

new 0.2.2 Oct 8, 2019
0.2.1 Aug 15, 2019
0.2.0 Jun 16, 2019
0.1.2 Feb 5, 2019

#149 in Rust patterns

Download history 67/week @ 2019-06-24 17/week @ 2019-07-01 16/week @ 2019-07-08 5/week @ 2019-07-22 4/week @ 2019-07-29 18/week @ 2019-08-05 10/week @ 2019-08-12 1/week @ 2019-08-19 56/week @ 2019-08-26 37/week @ 2019-09-02 9/week @ 2019-09-09 42/week @ 2019-09-16 12/week @ 2019-09-23 15/week @ 2019-09-30

72 downloads per month

Apache-2.0/MIT

16KB
230 lines

iterator-enum

crates-badge docs-badge license-badge rustc-badge

#[derive(Iterator, DoubleEndedIterator, ExactSizeIterator, Extend)] for enums.

Usage

Add this to your Cargo.toml:

[dependencies]
iterator-enum = "0.2"

The current iterator-enum requires Rust 1.31 or later.

Examples

use iterator_enum::*;

#[derive(Iterator, DoubleEndedIterator, ExactSizeIterator, FusedIterator, Extend)]
enum Either<A, B> {
    A(A),
    B(B),
}

fn foo(x: i32) -> impl Iterator<Item = i32> {
    if x > 0 {
        Either::A(x..=0)
    } else {
        Either::B(Some(x).into_iter())
    }
}

See auto_enums crate for how to automate patterns like this.

Supported traits

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0.6–1MB
~21K SLoC