macro_rules! enum_string { ( $(#[$attr:meta])* $vis:vis enum $name:ident { $($variant:ident => $value:expr),* $(,)? } ) => { ... }; }
Expand description
Generate an enum impl with string conversion methods.
ยงExamples
enum_string! {
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Foo {
Bar => "Bar",
Baz => "BAZ",
}
}
assert_eq!(&Foo::Bar.to_string(), "Bar");
assert_eq!(&Foo::Baz.to_string(), "BAZ");
This will generate a pub enum Foo
with variants Bar
and Baz
, which
implements std::str::FromStr
and std::fmt::Display
for the string
values specified.