#value #enumerate #information #help

no-std enumerable

A library helping you to enumerate all possible values of a type

7 releases (3 stable)

1.2.0 Jul 12, 2025
1.1.0 Dec 11, 2024
1.0.0 Jun 26, 2024
0.3.0 Jun 5, 2024
0.1.0 Apr 8, 2024

#684 in Rust patterns

Download history 127/week @ 2025-07-17 122/week @ 2025-07-24 31/week @ 2025-07-31 49/week @ 2025-08-07 347/week @ 2025-08-14 75/week @ 2025-08-21 161/week @ 2025-08-28 455/week @ 2025-09-04 143/week @ 2025-09-11 132/week @ 2025-09-18 457/week @ 2025-09-25 22/week @ 2025-10-02 144/week @ 2025-10-09 62/week @ 2025-10-16 29/week @ 2025-10-23 202/week @ 2025-10-30

443 downloads per month
Used in 7 crates (2 directly)

MIT license

36KB
617 lines

enumerable

Enumerate all possible values of a type.

Crates.io Version docs.rs GitHub License

See the examples for more examples and a guide on how to use the crate.

See the documentation for detailed information on the crate.

TL;DR

use enumerable::Enumerable;

#[derive(Debug, Copy, Clone, Enumerable)]
#[allow(dead_code)]
enum Food {
    Apple,
    Banana,
    Coffee { with_milk: bool },
}

#[derive(Debug, Copy, Clone, Enumerable)]
#[allow(dead_code)]
struct Meal {
    alice_eats: Food,
    bob_eats: Option<Food>,
    at_home: bool,
}

fn main() {
    println!("There are {} different meals, enumerated as follows:", Meal::ENUMERABLE_SIZE);
    for meal in Meal::enumerator() {
        println!("{:?}", meal);
    }
}

The code above will output:

There are 40 different meals, enumerated as follows:
Meal { alice_eats: Apple, bob_eats: None, at_home: false }
Meal { alice_eats: Apple, bob_eats: None, at_home: true }
Meal { alice_eats: Apple, bob_eats: Some(Apple), at_home: false }
Meal { alice_eats: Apple, bob_eats: Some(Apple), at_home: true }
Meal { alice_eats: Apple, bob_eats: Some(Banana), at_home: false }
Meal { alice_eats: Apple, bob_eats: Some(Banana), at_home: true }
Meal { alice_eats: Apple, bob_eats: Some(Coffee { with_milk: false }), at_home: false }
Meal { alice_eats: Apple, bob_eats: Some(Coffee { with_milk: false }), at_home: true }
Meal { alice_eats: Apple, bob_eats: Some(Coffee { with_milk: true }), at_home: false }
Meal { alice_eats: Apple, bob_eats: Some(Coffee { with_milk: true }), at_home: true }
Meal { alice_eats: Banana, bob_eats: None, at_home: false }
...

Dependencies

~3MB
~69K SLoC