Derive Macro VariantNames
#[derive(VariantNames)]
{
// Attributes available to this derive:
#[strum]
}
Expand description
Implements Strum::VariantNames which adds an associated constant VARIANTS which is a 'static slice 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};
// You need to import the trait, to have access to VARIANTS
use strum::VariantNames;
#[derive(Debug, EnumString, strum_macros::VariantNames)]
#[strum(serialize_all = "kebab-case")]
enum Color {
Red,
Blue,
Yellow,
RebeccaPurple,
}
assert_eq!(["red", "blue", "yellow", "rebecca-purple"], Color::VARIANTS);