Function sp_std::mem::variant_count [−][src]
pub const fn variant_count<T>() -> usize
🔬 This is a nightly-only experimental API. (
variant_count
)Returns the number of variants in the enum type T
.
If T
is not an enum, calling this function will not result in undefined behavior, but the
return value is unspecified. Equally, if T
is an enum with more variants than usize::MAX
the return value is unspecified. Uninhabited variants will be counted.
Examples
use std::mem; enum Void {} enum Foo { A(&'static str), B(i32), C(i32) } assert_eq!(mem::variant_count::<Void>(), 0); assert_eq!(mem::variant_count::<Foo>(), 3); assert_eq!(mem::variant_count::<Option<!>>(), 2); assert_eq!(mem::variant_count::<Result<!, !>>(), 2);