3 stable releases
Uses new Rust 2024
| 1.2.0 | Jun 20, 2025 |
|---|---|
| 1.1.0 | Apr 7, 2021 |
| 1.0.0 | Nov 1, 2018 |
#527 in Rust patterns
154,404 downloads per month
Used in 230 crates
(13 directly)
5KB
This crate provides VariantCount derive macro for enum which adds to it the VARIANT_COUNT constant,
containing count of enum variants.
Example
use variant_count::VariantCount;
#[derive(VariantCount)]
enum Test {
First(i32),
Second(Option<String>),
Third,
}
assert_eq!(Test::VARIANT_COUNT, 3);
Usage
If you're using Cargo, just add it to your Cargo.toml:
[dependencies]
variant_count = "1.2"
Use VariantCount in the derive enum attribute.
!
Enum variant count
This crate provides VariantCount derive macro for enum which adds to it the VARIANT_COUNT constant, containing count of enum variants.
The VariantCount usage example:
#[derive(VariantCount)]
enum Test {
First(i32),
Second(Option<String>),
Third,
}
assert_eq!(Test::VARIANT_COUNT, 3);
Usage
If you're using Cargo, just add it to your Cargo.toml:
[dependencies]
variant_count = "1.2"
License
MIT
Dependencies
~150–560KB
~13K SLoC