#enums #string #utility-macro #pino #function

macro pino_enum_string

general rust utility functions and macros

1 unstable release

0.1.0 Nov 19, 2022

#26 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
~37K SLoC