#enums #str #static #convert #derive #ref

macro enum_to_str_derive

provide a simple way to convert enum to static str ref

4 releases (2 breaking)

Uses old Rust 2015

0.3.0 Sep 14, 2018
0.2.1 Jun 2, 2018
0.2.0 Jun 2, 2018
0.1.0 Sep 14, 2017

#1908 in Procedural macros

BSD-3-Clause

4KB
69 lines

Latest Version License Build state

example

main.rs

#[macro_use]
extern crate enum_to_str_derive;

#[derive(EnumToStr)]
enum Foo {
    Foo,
    #[ETS(value = r#"Can you please tell me what does "foo" mean"#)]
    Question,
}

fn main() {
    debug_assert_eq!("Foo", Foo::Foo.enum_to_str());
    debug_assert_eq!(
        r#"Can you please tell me what does "foo" mean"#,
        Foo::Question.enum_to_str()
    );
}

TODO

  • add attribute: value
  • add attribute: handler

Dependencies

~2MB
~46K SLoC