Crates.io | arg_enum_proc_macro |
lib.rs | arg_enum_proc_macro |
version | 0.3.4 |
source | src |
created_at | 2019-03-11 17:28:56.49842 |
updated_at | 2023-09-12 12:39:27.238891 |
description | A procedural macro compatible with clap arg_enum |
homepage | |
repository | https://github.com/lu-zero/arg_enum_proc_macro |
max_upload_size | |
id | 120087 |
size | 16,298 |
arg_enum!
from clapIn 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,
}
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,
}