enum-info 1.0.3

A crate to generate enum impls which can list basic info about an enum.
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented1 out of 2 items with examples
  • Size
  • Source code size: 29.12 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 309.67 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 4s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • CalinZBaenen/enum-info
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • CalinZBaenen

enum-info

Overview

enum-info is a simple crate intended for the niche scenario where you need to know the number of variants an enum has, as well as having a list of each variant (for enums consisting of only unit variants).

Example

Imagine making a game where you can select between multiple characters — in Rust, this selection would be represented by an enum.

In order to make a character select menu that can seamlessly handle the addition of new characters, you'd usually have to track all the members of the enum and manually update the size of some array; however, with this library, it's as simple as:

#[enum_info]
enum Characters {
	Katty,
	Jax
}

// ...

assert_eq!(Characters::variant_count(), 2);
assert_eq!(Characters::VARIANTS, [Characters::Katty, Characters::Jax]);