#iterator #enums #derive #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

#1180 in Rust patterns

Download history 662/week @ 2023-11-20 600/week @ 2023-11-27 692/week @ 2023-12-04 1032/week @ 2023-12-11 1066/week @ 2023-12-18 415/week @ 2023-12-25 724/week @ 2024-01-01 872/week @ 2024-01-08 767/week @ 2024-01-15 731/week @ 2024-01-22 488/week @ 2024-01-29 955/week @ 2024-02-05 805/week @ 2024-02-12 1102/week @ 2024-02-19 960/week @ 2024-02-26 962/week @ 2024-03-04

3,879 downloads per month
Used in 32 crates (6 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

~340–790KB
~18K SLoC