Enum with iterator over all variants

I want to make some enums in which each variant is atomic, e.g.

enum Thingy {
    Foo,
    Bar,
    Baz,
}

and I want to be able to iterate over all the variants, approximately like this

for variant in Thingy::variants() { ... }

What would be an idiomatic way of doing this?

You might be looking for strum::EmumIter.

5 Likes