enumerable

Crates.ioenumerable
lib.rsenumerable
version
sourcesrc
created_at2024-04-08 09:36:12.795505
updated_at2024-12-11 15:18:15.257927
descriptionA library helping you to enumerate all possible values of a type
homepage
repositoryhttps://github.com/GeminiLab/enumerable/
max_upload_size
id1200068
Cargo.toml error:TOML parse error at line 25, column 1 | 25 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Su Mingxian (aarkegz)

documentation

README

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 }
...
Commit count: 117

cargo fmt