[−][src]Type Definition structural::enums::VariantCountOut
type VariantCountOut<This> = <This as VariantCount>::Count;
Queries the amount of variants of This
.
This evaluates to a TStr,like TS!(9)
Example
This demonstrates VariantCountOut
by
making a function that requires two enums to have the same number of variants.
use structural::Structural; use structural::enums::{VariantCount,VariantCountOut}; same_sized_enums( &Enum1::Foo, &Enum2::A ); // This does not compile because `Enum1` has 3 variants and `Result` has 2 variants. // same_sized_enums( &Enum1::Foo, &Result::<(),()>::Ok(()) ); // This function asserts at compile-time that both enums have the same number of variants. fn same_sized_enums<L,R>(left:&L,right:&R) where L:VariantCount, R:VariantCount<Count=VariantCountOut<L>>, {} #[derive(Structural)] enum Enum1{ Foo, Bar, Baz, } #[derive(Structural)] enum Enum2{ A, B, C, }