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

#756 in Procedural macros

Download history 5856/week @ 2024-01-03 7035/week @ 2024-01-10 5984/week @ 2024-01-17 6395/week @ 2024-01-24 5555/week @ 2024-01-31 6637/week @ 2024-02-07 5863/week @ 2024-02-14 5994/week @ 2024-02-21 5310/week @ 2024-02-28 9651/week @ 2024-03-06 22665/week @ 2024-03-13 37741/week @ 2024-03-20 38551/week @ 2024-03-27 38014/week @ 2024-04-03 38922/week @ 2024-04-10 34138/week @ 2024-04-17

156,016 downloads per month
Used in 25 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

~305–760KB
~18K SLoC