#proc_macro #arg_enum

macro arg_enum_proc_macro

A procedural macro compatible with clap arg_enum

2 releases

✓ Uses Rust 2018 edition

0.1.1 Mar 11, 2019
0.1.0 Mar 11, 2019

#193 in Rust patterns

Download history 859/week @ 2019-03-10 546/week @ 2019-03-17 538/week @ 2019-03-24 416/week @ 2019-03-31 434/week @ 2019-04-07 418/week @ 2019-04-14 448/week @ 2019-04-21 214/week @ 2019-04-28

733 downloads per month

MIT license

6KB
72 lines

Procedural macro derive that mimics arg_enum! from clap

Usage

In Cargo.toml:

[dependencies]
arg_enum_proc_macro = "0.1"

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,
}

lib.rs:

arg_enum_proc_macro

This crate consists in a procedural macro derive that provides the same implementations that clap the clap::arg_enum macro provides: [std::fmt::Display], [std::str::FromStr] and a variants() function.

By using a procedural macro it allows documenting the enum fields correctly and avoids the requirement of expanding the macro to use the structure with cbindgen.

Dependencies

~773KB
~17K SLoC