#proc-macro #enum-variant #static #list #expose

enumly

Provides a procedural macro that exposes a compile-time static list of all variants of an enum

1 stable release

Uses new Rust 2024

1.1.1 Dec 17, 2025

#1698 in Rust patterns

MIT license

4KB

enumly

Github Crates.io Docs.rs Build

Provides a procedural macro that exposes a compile-time static list of all variants of an enum.

Usage

use enumly::Enumly;

#[derive(Enumly, Debug, PartialEq)]
enum Color {
    Red,
    Green,
    Blue,
}

assert_eq!(Color::COUNT, 3);
assert_eq!(Color::VARIANTS, &[Color::Red, Color::Green, Color::Blue]);

What does not work

Non-unit variants are rejected at compile time:

use enumly::Enumly;

#[derive(Enumly)]
enum Bad {
    Tuple(u8),
    Struct { value: u8 },
}

Dependencies

~130–520KB
~12K SLoC