auto-variants 0.1.0

A macro that exposes a function that returns all enum variants.
Documentation
  • Coverage
  • 25%
    1 out of 4 items documented0 out of 2 items with examples
  • Size
  • Source code size: 5.75 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 242.82 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • AshrafIbrahim03/auto-variants
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • AshrafIbrahim03

Auto Variants

This is a crate that exposes a derive macro that returns all of an enum's variants. Here's a simple example:

#[derive(Variants, PartialEq, Debug)]
enum Directions {
    Up,
    Down,
    Left,
    Right,
}
let correct_list = [
  Directions::Up,
  Directions::Down,
  Directions::Left,
  Directions::Right,
];
assert_eq!(correct_list, Directions::variants());
assert_eq!(correct_list, Directions::VARIANTS);

This is a pretty small example, but might save a lot of time if it's a big enum.

This is implemented so that a fixed sized array is made at compile time that is made up of all enum variants. A reference is returned when using the variants method, and the VARIANTS is the constant array that variants references.