Can rust build enums dynamically / at runtime?

So a GUI library I'm using needs me to supply it an enum so that I can have radio buttons, with the one currently selected corresponding to the variant held by AppState.

I want a radio button for every folder in a given directory.

But I can't know in advance which folders will be present.

I think I can cheat however... I think I can pass it an Option<usize> so that it returns me a Some(index) into a vector, with a bonus of adding an hidden offscreen radiobutton set to None so that I can also display None selected.

But it had me thinking, is there a way to build enums at run time?

No, you should use a vector with index or similar.

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.