Skip to main content

EnumAll

Derive Macro EnumAll 

Source
#[derive(EnumAll)]
{
    // Attributes available to this derive:
    #[enum_all]
}
Expand description

Generate an array of all variants and a variant count.

This macro generates inherent constants on the enum:

  • const ALL: [Self; N]
  • const COUNT: usize

ALL requires unit enums (it builds an array of variant values). For non-unit enums, use #[enum_all(all(disable))] to derive only COUNT, or #[enum_all(skip)] on the non-unit variants.

§Container attributes

  • #[enum_all(all(name = ..., vis = "...", enable/disable))]: control the ALL constant
  • #[enum_all(count(name = ..., vis = "...", enable/disable))]: control the COUNT constant

§Variant attributes

  • #[enum_all(skip)]: exclude this variant from ALL and COUNT

§Example

use enum_helper::EnumAll;

#[derive(EnumAll, Debug, PartialEq, Eq)]
enum Foo {
    Bar,
    Baz,
    #[enum_all(skip)]
    Skipped
}

assert_eq!(Foo::ALL, [Foo::Bar, Foo::Baz]);
assert_eq!(Foo::COUNT, 2);