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

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.