Crates.io | enum-each-variant-derive |
lib.rs | enum-each-variant-derive |
version | 0.1.3 |
source | src |
created_at | 2018-03-29 20:56:03.422714 |
updated_at | 2018-12-03 22:14:55.302682 |
description | Background jobs for Rust |
homepage | https://github.com/davidpdrsn/enum-each-variant-derive |
repository | https://github.com/davidpdrsn/enum-each-variant-derive.git |
max_upload_size | |
id | 58121 |
size | 4,159 |
#[derive(EachVariant)]
Derive method that returns each variant of an enum
#[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]);
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),
}