#iterator #derive #enum

macro no-std iter-enum

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

7 releases (2 stable)

1.0.1 Apr 6, 2021
1.0.0 Jan 27, 2021
0.2.7 Jan 5, 2021
0.2.6 Dec 29, 2020
0.2.3 Nov 22, 2019

#188 in Rust patterns

Download history 85/week @ 2020-12-24 954/week @ 2020-12-31 1076/week @ 2021-01-07 575/week @ 2021-01-14 1127/week @ 2021-01-21 1813/week @ 2021-01-28 889/week @ 2021-02-04 615/week @ 2021-02-11 826/week @ 2021-02-18 742/week @ 2021-02-25 1133/week @ 2021-03-04 998/week @ 2021-03-11 1059/week @ 2021-03-18 1082/week @ 2021-03-25 901/week @ 2021-04-01 924/week @ 2021-04-08

4,175 downloads per month
Used in 13 crates (3 directly)

Apache-2.0 OR MIT

16KB
189 lines

iter-enum

crates.io docs.rs license rustc build status

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

Usage

Add this to your Cargo.toml:

[dependencies]
iter-enum = "1"

Compiler support: requires rustc 1.31+

Examples

use iter_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

Optional features

  • rayon
    • Enable to use #[derive(ParallelIterator, IndexedParallelIterator, ParallelExtend)].

Related Projects

  • auto_enums: A library for to allow multiple return types by automatically generated enum.
  • derive_utils: A procedural macro helper for easily writing derives macros for enums.
  • futures-enum: #[derive(Future, Stream, Sink, AsyncRead, AsyncWrite, AsyncSeek, AsyncBufRead)] for enums.
  • io-enum: #[derive(Read, Write, Seek, BufRead)] for enums.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

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.4–0.8MB
~20K SLoC