arg_enum_proc_macro

Crates.ioarg_enum_proc_macro
lib.rsarg_enum_proc_macro
version0.3.4
sourcesrc
created_at2019-03-11 17:28:56.49842
updated_at2023-09-12 12:39:27.238891
descriptionA procedural macro compatible with clap arg_enum
homepage
repositoryhttps://github.com/lu-zero/arg_enum_proc_macro
max_upload_size
id120087
size16,298
Luca Barbato (lu-zero)

documentation

README

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,
}
Commit count: 21

cargo fmt