#proc-macro #enums #procedural #clap #foo #macro-derive #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

#935 in Procedural macros

Download history 6029/week @ 2023-11-23 5125/week @ 2023-11-30 4224/week @ 2023-12-07 4827/week @ 2023-12-14 3258/week @ 2023-12-21 4395/week @ 2023-12-28 6178/week @ 2024-01-04 6726/week @ 2024-01-11 6063/week @ 2024-01-18 6370/week @ 2024-01-25 5579/week @ 2024-02-01 6627/week @ 2024-02-08 6048/week @ 2024-02-15 5777/week @ 2024-02-22 5544/week @ 2024-02-29 7045/week @ 2024-03-07

25,282 downloads per month
Used in 22 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

~325–780KB
~19K SLoC