#proc-macro #arg-enum

arg_enum_proc_macro

A procedural macro compatible with clap arg_enum

6 releases

0.3.2 Nov 18, 2021
0.3.1 Jan 25, 2021
0.3.0 Aug 28, 2019
0.2.0 Aug 18, 2019
0.1.1 Mar 11, 2019

#35 in Procedural macros

Download history 1660/week @ 2021-08-10 2040/week @ 2021-08-17 2389/week @ 2021-08-24 2404/week @ 2021-08-31 2639/week @ 2021-09-07 2622/week @ 2021-09-14 2029/week @ 2021-09-21 3356/week @ 2021-09-28 2534/week @ 2021-10-05 3044/week @ 2021-10-12 3316/week @ 2021-10-19 3623/week @ 2021-10-26 4280/week @ 2021-11-02 3148/week @ 2021-11-09 6535/week @ 2021-11-16 3048/week @ 2021-11-23

17,855 downloads per month
Used in 13 crates (2 directly)

MIT license

13KB
192 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

~295–710KB
~18K SLoC