#enum #derive #variant #count

macro variant_count

Derive macro for enum which adds to it the count of variants

1 stable release

1.0.0 Nov 1, 2018

#641 in Rust patterns

Download history 9/week @ 2020-03-08 4/week @ 2020-03-15 161/week @ 2020-03-22 116/week @ 2020-03-29 7/week @ 2020-04-05 15/week @ 2020-04-12 4/week @ 2020-04-19 4/week @ 2020-04-26 4/week @ 2020-05-03 13/week @ 2020-05-17 5/week @ 2020-05-24 5/week @ 2020-05-31 2/week @ 2020-06-07 2/week @ 2020-06-14 4/week @ 2020-06-21

117 downloads per month
Used in 3 crates (2 directly)

MIT license

4KB

Enum variant count

Crates.io Docs

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 = "*"

License

MIT


lib.rs:

This crate provides VariantCount derive macro for enum which adds to it the VARIANT_COUNT constant, containing count of enum variants.

Example

extern crate variant_count;

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 = "*"

Use VariantCount in the derive enum attribute. !

Dependencies

~1MB
~30K SLoC