https://github.com/lu-zero/arg_enum_proc_macro
clap.rs arg_enum made procedural
https://github.com/lu-zero/arg_enum_proc_macro
Last synced: 8 months ago
JSON representation
clap.rs arg_enum made procedural
- Host: GitHub
- URL: https://github.com/lu-zero/arg_enum_proc_macro
- Owner: lu-zero
- License: mit
- Created: 2019-03-11T17:27:32.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-09-12T12:40:34.000Z (over 2 years ago)
- Last Synced: 2024-05-02T00:13:43.632Z (over 1 year ago)
- Language: Rust
- Size: 15.6 KB
- Stars: 4
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Procedural macro derive that mimics `arg_enum!` from [clap](https://clap.rs)


[](https://deps.rs/repo/github/lu-zero/arg_enum_proc_macro)
## Usage
In `Cargo.toml`:
``` toml
[dependencies]
arg_enum_proc_macro = "0.3"
```
In the rust code:
``` rust
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:
``` rust
/// 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,
}
```