#enums #macro

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

#709 in #enums

Download history 56/week @ 2025-10-22 12/week @ 2025-10-29 34/week @ 2025-11-05 27/week @ 2025-11-12 21/week @ 2025-11-19 23/week @ 2025-11-26 31/week @ 2025-12-03 15/week @ 2025-12-10 27/week @ 2025-12-17 22/week @ 2025-12-24 24/week @ 2025-12-31 10/week @ 2026-01-07 10/week @ 2026-01-14 24/week @ 2026-01-21 23/week @ 2026-01-28 21/week @ 2026-02-04

78 downloads per month
Used in 7 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

~135–520KB
~12K SLoC