#iterator #enums #derive #double-ended #no-alloc

macro no-std iter-enum

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

12 releases (7 stable)

1.1.3 Jan 27, 2024
1.1.1 Jun 29, 2023
1.1.0 Mar 26, 2023
1.0.2 Dec 10, 2022
0.2.3 Nov 22, 2019

#2759 in Rust patterns

Download history 1861/week @ 2024-08-25 1343/week @ 2024-09-01 1309/week @ 2024-09-08 777/week @ 2024-09-15 1188/week @ 2024-09-22 928/week @ 2024-09-29 689/week @ 2024-10-06 710/week @ 2024-10-13 914/week @ 2024-10-20 907/week @ 2024-10-27 1610/week @ 2024-11-03 1075/week @ 2024-11-10 1185/week @ 2024-11-17 818/week @ 2024-11-24 1547/week @ 2024-12-01 1288/week @ 2024-12-08

4,925 downloads per month
Used in 38 crates (5 directly)

Apache-2.0 OR MIT

22KB
172 lines

iter-enum

crates.io docs.rs license rust version github actions

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

Usage

Add this to your Cargo.toml:

[dependencies]
iter-enum = "1"

Compiler support: requires rustc 1.56+

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

~255–700KB
~16K SLoC