| Crates.io | auto-variants |
| lib.rs | auto-variants |
| version | 0.1.0 |
| created_at | 2025-05-28 21:51:13.39368+00 |
| updated_at | 2025-05-28 21:51:13.39368+00 |
| description | A macro that exposes a function that returns all enum variants. |
| homepage | |
| repository | https://github.com/AshrafIbrahim03/auto-variants.git |
| max_upload_size | |
| id | 1693293 |
| size | 5,754 |
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.