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

#698 in Procedural macros

Download history 25577/week @ 2024-03-14 39268/week @ 2024-03-21 37979/week @ 2024-03-28 37981/week @ 2024-04-04 40042/week @ 2024-04-11 39205/week @ 2024-04-18 46610/week @ 2024-04-25 53305/week @ 2024-05-02 51046/week @ 2024-05-09 51645/week @ 2024-05-16 39239/week @ 2024-05-23 35988/week @ 2024-05-30 36868/week @ 2024-06-06 42552/week @ 2024-06-13 42842/week @ 2024-06-20 38899/week @ 2024-06-27

167,117 downloads per month
Used in 32 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

~280–730KB
~18K SLoC