[][src]Derive Macro string_enum::StringEnum

#[derive(StringEnum)]

Creates .as_str() and then implements Debug and Display using it.

Input

Enum with `str_value`-style doc comment for each variant.

e.g.

 pub enum BinOp {
     /// `+`
     Add,
     /// `-`
     Minus,
 }

Currently, `str_value` must be live in it's own line.

Output

Example

 #[macro_use]
 extern crate string_enum;
 extern crate serde;

 #[derive(StringEnum)]
 pub enum Tokens {
     /// `a`
     A,
     /// `bar`
     B,
 }

 assert_eq!(Tokens::A.as_str(), "a");
 assert_eq!(Tokens::B.as_str(), "bar");

 assert_eq!(Tokens::A.to_string(), "a");
 assert_eq!(format!("{:?}", Tokens::A), format!("{:?}", "a"));

All formatting flags are handled correctly.