Derive Macro strum::EnumVariantNames

#[derive(EnumVariantNames)]
{
    // Attributes available to this derive:
    #[strum]
}
Available on crate feature derive only.
Expand description

Implements Strum::VariantNames which adds an associated constant VARIANTS which is an array of discriminant names.

Adds an impl block for the enum that adds a static VARIANTS array of &'static str that are the discriminant names. This will respect the serialize_all attribute on the enum (like #[strum(serialize_all = "snake_case")].

// import the macros needed
use strum_macros::{EnumString, EnumVariantNames};
// You need to import the trait, to have access to VARIANTS
use strum::VariantNames;

#[derive(Debug, EnumString, EnumVariantNames)]
#[strum(serialize_all = "kebab_case")]
enum Color {
    Red,
    Blue,
    Yellow,
    RebeccaPurple,
}
assert_eq!(["red", "blue", "yellow", "rebecca-purple"], Color::VARIANTS);