#iterator #derive #enum

macro no-std iter-enum

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

8 releases (3 stable)

1.0.2 Dec 10, 2022
1.0.1 Apr 6, 2021
1.0.0 Jan 27, 2021
0.2.7 Jan 5, 2021
0.2.3 Nov 22, 2019

#124 in #enum

Download history 339/week @ 2022-11-29 420/week @ 2022-12-06 561/week @ 2022-12-13 374/week @ 2022-12-20 219/week @ 2022-12-27 267/week @ 2023-01-03 500/week @ 2023-01-10 329/week @ 2023-01-17 434/week @ 2023-01-24 473/week @ 2023-01-31 327/week @ 2023-02-07 448/week @ 2023-02-14 453/week @ 2023-02-21 481/week @ 2023-02-28 368/week @ 2023-03-07 356/week @ 2023-03-14

1,719 downloads per month
Used in 20 crates (4 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)].
  • 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.
  • 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.7–1MB
~27K SLoC