Derive Macro strum_macros::EnumCount
source · #[derive(EnumCount)]
{
// Attributes available to this derive:
#[strum]
}
Expand description
Add a constant usize
equal to the number of variants.
For a given enum generates implementation of strum::EnumCount
,
which adds a static property COUNT
of type usize that holds the number of variants.
use strum::{EnumCount, IntoEnumIterator};
use strum_macros::{EnumCount as EnumCountMacro, EnumIter};
#[derive(Debug, EnumCountMacro, EnumIter)]
enum Week {
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
}
assert_eq!(7, Week::COUNT);
assert_eq!(Week::iter().count(), Week::COUNT);