#enums #macro #utils

macro enum_all_variants

Generate a list of all enum variants in Rust

2 unstable releases

0.2.0 Mar 18, 2024
0.1.0 Oct 10, 2023

#1676 in Procedural macros

Download history 7/week @ 2024-07-04 12/week @ 2024-07-11 7/week @ 2024-07-18 44/week @ 2024-07-25 23/week @ 2024-08-01 18/week @ 2024-08-08 21/week @ 2024-08-15 29/week @ 2024-08-22 42/week @ 2024-08-29 4/week @ 2024-09-05 1/week @ 2024-09-12 35/week @ 2024-09-19

88 downloads per month
Used in 6 crates (2 directly)

MIT license

4KB
58 lines

enum_all_variants

Proc macro for generating a list of all enum variants.

Example

use enum_all_variants::AllVariants;

#[derive(AllVariants, Debug)]
enum Direction {
    Left,
    Top,
    Right,
    Bottom,
}

fn main() {
    println!("{:?}", Direction::all_variants());
}

Outputs:

[Left, Top, Right, Bottom]

Dependencies

~275–730KB
~17K SLoC