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

#819 in Procedural macros

Download history 62541/week @ 2024-09-16 70760/week @ 2024-09-23 68177/week @ 2024-09-30 70817/week @ 2024-10-07 76874/week @ 2024-10-14 72403/week @ 2024-10-21 79288/week @ 2024-10-28 80709/week @ 2024-11-04 80139/week @ 2024-11-11 76743/week @ 2024-11-18 82763/week @ 2024-11-25 85091/week @ 2024-12-02 86202/week @ 2024-12-09 83670/week @ 2024-12-16 52636/week @ 2024-12-23 50505/week @ 2024-12-30

280,141 downloads per month
Used in 83 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

~215–660KB
~16K SLoC