This crate provides the VariantCount derive macro, which adds to an enum a VARIANT_COUNT constant holding the number of its variants.
The VariantCount usage example:
#[derive(VariantCount)]
enum Test {
First(i32),
Second(Option<String>),
Third,
}
assert_eq!(Test::VARIANT_COUNT, 3);If you're using Cargo, just add it to your Cargo.toml:
[dependencies]
variant_count = "1.2"Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or opensource.org/licenses/MIT)
at your option.