Add a way to iterate over all values in any enum

I believe it could be good to add a way to iterate over all values of any enum, I fell there are a lot of use cases for it

The strum crate provides this with #[derive(EnumIter)].

1 Like

Do you mean over C-like or an enum where all variants are non-tuple and non-struct? As an example, what are the values of

enum Hmm {


enum Weird {

I don't think I've ever wanted iteration for such an enum, but strum opts for [Big(0), Other]. I think a derive macro which recursively iterates enums could be derived from strum's macro, if that's what's desired.

I can't say I've wanted it either, but "all values of any enum" is quite a bit more than what strum is doing there. Of course, this isn't even in a pre-pre-pre-RFC form, so knowing whether such a phrasing is intentional or not realizing what such a phrasing would imply is difficult to discern without asking such questions (IMO).


Usually what I need is a visitor or mutable visitor on such types to do recursive descent on every field. There's no sugar for it, but the code is straightforward and a proc-macro (or even a regular macro) can be written for it too.

1 Like

Anything prevents from implementing an Iterator for the enum? I don't really see the use case, though. Can you explain one or two of them?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.