4 releases

Uses old Rust 2015

0.1.3 Dec 3, 2018
0.1.2 Mar 29, 2018
0.1.1 Mar 29, 2018
0.1.0 Mar 29, 2018

#29 in #background-jobs

MIT license

5KB

#[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),
}

lib.rs:

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),
}

Dependencies

~2MB
~46K SLoC