#proc-macro #arg-enum

macro arg_enum_proc_macro

A procedural macro compatible with clap arg_enum

8 releases

0.3.4 Sep 12, 2023
0.3.3 Sep 12, 2023
0.3.2 Nov 18, 2021
0.3.1 Jan 25, 2021
0.1.1 Mar 11, 2019

#1601 in Procedural macros

Download history 350724/week @ 2025-09-30 333950/week @ 2025-10-07 341419/week @ 2025-10-14 353686/week @ 2025-10-21 380450/week @ 2025-10-28 407078/week @ 2025-11-04 390107/week @ 2025-11-11 405885/week @ 2025-11-18 302959/week @ 2025-11-25 311475/week @ 2025-12-02 331395/week @ 2025-12-09 303822/week @ 2025-12-16 222666/week @ 2025-12-23 240027/week @ 2025-12-30 349114/week @ 2026-01-06 347242/week @ 2026-01-13

1,205,907 downloads per month
Used in 181 crates (via rav1e)

MIT license

13KB
169 lines

Procedural macro derive that mimics arg_enum! from clap

Crates.io docs.rs dependency status

Usage

In Cargo.toml:

[dependencies]
arg_enum_proc_macro = "0.3"

In the rust code:

use arg_enum_proc_macro::ArgEnum;

/// All the possible states of Foo
#[derive(ArgEnum)]
pub enum Foo {
    /// Initial state
    Unk,
    /// Foo is on
    On,
    /// Foo is off
    Off,
}

Aliases

It is possible to express an alias using the attribute arg_enum(alias = "AliasVariant"). The FromStr will map the "AliasVariant" string to the decorated enum variant:

/// All the possible states of Foo
#[derive(ArgEnum)]
pub enum Foo {
    /// Initial state
    Unk,
    /// Foo is on
    #[arg_enum(alias = "Up")]
    On,
    /// Foo is off
    #[arg_enum(alias = "Down")]
    Off,
}

Dependencies

~130–510KB
~12K SLoC