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

#830 in Procedural macros

Download history 77886/week @ 2024-11-17 81464/week @ 2024-11-24 84680/week @ 2024-12-01 87017/week @ 2024-12-08 83058/week @ 2024-12-15 53399/week @ 2024-12-22 56464/week @ 2024-12-29 88828/week @ 2025-01-05 112832/week @ 2025-01-12 92511/week @ 2025-01-19 99027/week @ 2025-01-26 108204/week @ 2025-02-02 114057/week @ 2025-02-09 117263/week @ 2025-02-16 129794/week @ 2025-02-23 116464/week @ 2025-03-02

487,478 downloads per month
Used in 89 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

~190–620KB
~15K SLoC