Crate enum_kinds [−] [src]
Custom derive for generating enums with matching variants but without any of the data.
In other words, enum-kinds
automatically generates enums that have the
same set of variants as the original enum, but with all the embedded data
stripped away (that is, all the variants of the newly generated enum are
unit variants). Additionally, enum-kinds
implements From
trait for going
from the original enum to the unit variant version.
The crate is compatible with stable Rust releases. This crate replaces
earlier enum_kinds_macros
and enum_kinds_traits
crates.
Example
ⓘThis example is not tested
#[macro_use] extern crate enum_kinds; #[derive(EnumKind)] #[enum_kind_name(SomeEnumKind)] enum SomeEnum { First(String, u32), Second(char), Third } #[test] fn test_enum_kind() { let first = SomeEnum::First("Example".to_owned(), 32); assert_eq!(SomeEnumKind::from(&first), SomeEnumKind::First); }
The #[derive(EnumKind)]
attribute automatically creates another enum
named
SomeEnumKind
that contains matching unit variant for each of the variants in
SomeEnum
.
Functions
enum_kind |