Print complete enum
Hi,
I would like to print all variants of an enum. So e.g. for
enum Foo {
Abc,
Xyz,
}
I would like to see something like "Abc/Xyz"
.
I implemented Display
for Foo
like this ...
impl Display for Foo {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{:?}/{:?}", Foo::Abc, Foo::Xyz)
}
}
and then could do it with println!("{}", Foo::Abc)
but using a variant to print the whole enum feels wrong.
Then I tried to use Action::iter()
from the strum
crate but could not figure out how to use it properly.
Any idea how this could be done?
Thanks.
Source: View source