test_output_directory/
macros.rs1#[macro_export]
8macro_rules! enumerable_enum {
9 ($(#[$meta:meta])* $name:ident {
10 $($(#[$variant_meta:meta])* $variant:ident),*,
11 }) => {
12 $(#[$meta])*
13 pub enum $name {
14 $($(#[$variant_meta])* $variant),*
15 }
16
17 impl $name {
18 pub fn all_variants() -> Vec<Self> {
19 vec![
20 $($name::$variant),*
21 ]
22 }
23 }
24 }
25}
26
27#[cfg(test)]
28mod test {
29 #[test]
30 fn test_all_variants() {
31 enumerable_enum! {
32 #[derive(Debug, PartialEq)]
33 TestEnum {
34 VarOne,
35 VarTwo,
36 }
37 }
38
39 assert_eq!(TestEnum::all_variants(), vec![TestEnum::VarOne, TestEnum::VarTwo,]);
40 }
41}