use discriminant::{Discriminant, Enum}; #[derive(Enum)] #[allow(unused)] #[repr(u8)] pub enum MixedEnum { UnitVariantA = 1, TupleVariantB(i32, f64), StructVariantC { name: String, value: T }, SomeValue(T), NoneValue = 99, TupleWithGeneric(T, usize), } #[test] fn test() { assert_eq!( as Enum>::Discriminant::all().collect::>(), vec![ as Enum>::Discriminant::UnitVariantA, as Enum>::Discriminant::TupleVariantB, as Enum>::Discriminant::StructVariantC, as Enum>::Discriminant::SomeValue, as Enum>::Discriminant::NoneValue, as Enum>::Discriminant::TupleWithGeneric, ] ); assert_eq!( std::convert::identity::(MixedEnum::<()>::UnitVariantA.discriminant().into()), 1 ); assert_eq!( std::convert::identity::(MixedEnum::<()>::SomeValue(()).discriminant().into()), 4 ); }