1 unstable release

0.1.0 Nov 19, 2022

#23 in #utility-macro


Used in pino_utils

MIT/Apache

5KB
72 lines

pino_enum_string

Derive macro for Deref and DerefMut

crates.io docs.rs MIT/Apache 2.0

Example usage

use pino_enum_string::enum_string;

#[enum_string]
enum Weapon {
    Red,
    Blue,
    Green,
}

fn main() {
    assert_eq!("Red", Weapon::Red.to_string());
    assert_eq!("Blue", Weapon::Blue.to_string());
    assert_eq!("Green", Weapon::Green.to_string());
}

lib.rs:

Derive macro to implement display for each variant of enum

use pino_enum_string::enum_string;

#[enum_string]
enum Weapon {
    Red,
    Blue,
    Green,
}

fn main() {
    assert_eq!("Red", Weapon::Red.to_string());
    assert_eq!("Blue", Weapon::Blue.to_string());
    assert_eq!("Green", Weapon::Green.to_string());
}

Dependencies

~1.5MB
~36K SLoC