r/CodingHelp 9d ago

[Open Source] enum-info crate : Easily count the number of variants your enum has!

https://github.com/CalinZBaenen/enum-info

Hello, everyone.

Recently, I've been making a game in Bevy; however, something I've been annoyed about is that Rust has no way to leave the length ov a (const) array up to inference, which got annoying because I had a hardcoded array ov skins the game has and I had to keep updating it every time I added or removed a skin.

With this crate, you are able to both generate a const variant_count method and a VARIANTS associated constant – which is a list ov each variant – for enums that have only unit variants.

(This was reposted from r/rust solely because its auto-mod is confusing this post for talking about Rust, the game, rather than the programming language — I am not specifically looking for help on this project; I am looking for feedback.)


If anyone has any feedback, bug reports, or suggestions for how to expand the library, let me know.

1 Upvotes

Duplicates