enum-each-variant-derive

Crates.ioenum-each-variant-derive
lib.rsenum-each-variant-derive
version0.1.3
sourcesrc
created_at2018-03-29 20:56:03.422714
updated_at2018-12-03 22:14:55.302682
descriptionBackground jobs for Rust
homepagehttps://github.com/davidpdrsn/enum-each-variant-derive
repositoryhttps://github.com/davidpdrsn/enum-each-variant-derive.git
max_upload_size
id58121
size4,159
David Pedersen (davidpdrsn)

documentation

README

#[derive(EachVariant)]

Derive method that returns each variant of an enum

Sample usage

#[macro_use]
extern crate enum_each_variant_derive;

#[derive(EachVariant, Eq, PartialEq, Debug)]
enum Thing {
    One,
    Two,
    Three,
    Four,
}

let all: Vec<Thing> = Thing::all_variants();

assert_eq!(all, vec![Thing::One, Thing::Two, Thing::Three, Thing::Four]);

Gotcha

Only works on enums where no variants have associated values. So we wouldn't be able to use it for this enum:

enum TrainStatus {
    OnTime,
    DelayedBy(std::time::Duration),
}
Commit count: 10

cargo fmt