strum_macros

Derive Macro VariantArray

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

Adds a 'static slice with all of the Enum’s variants.

Implements strum::VariantArray which adds an associated constant VARIANTS. This constant contains an array with all the variants of the enumerator.

This trait can only be autoderived if the enumerator is composed only of unit-type variants, meaning that the variants must not have any data.

use strum::VariantArray;

#[derive(VariantArray, Debug, PartialEq, Eq)]
enum Op {
    Add,
    Sub,
    Mul,
    Div,
}

assert_eq!(Op::VARIANTS, &[Op::Add, Op::Sub, Op::Mul, Op::Div]);