#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

#93 in Procedural macro helpers

Download history

5 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

~796KB
~18K SLoC