I am trying to define a stringy_enum!
macro that will save me some typing when converting to and from strings:
However, when I call stringy_enum!(FooBar => [Foo, Bar, Baz])
, the compiler complains that Foo
, Bar
and Baz
are undefined in this scope. I thought that the hole point of this exercise was to write a macro that defines those symbols, but apparently I am missing something.
My question is two fold:
- How to define a symbol (in this case an
enum
variant) usingmacro_rules!
- Is there a more idiomatic way to define an
enum
that can parse and display itself, e.g."Foo" -> Foobar::Foo
andFoobar::Foo -> "Foo"
?
edit: fixed playground link