auto-variants

Crates.ioauto-variants
lib.rsauto-variants
version0.1.0
created_at2025-05-28 21:51:13.39368+00
updated_at2025-05-28 21:51:13.39368+00
descriptionA macro that exposes a function that returns all enum variants.
homepage
repositoryhttps://github.com/AshrafIbrahim03/auto-variants.git
max_upload_size
id1693293
size5,754
(AshrafIbrahim03)

documentation

README

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.

Commit count: 0

cargo fmt