Skip to main content

EnumKind

Derive Macro EnumKind 

Source
#[derive(EnumKind)]
{
    // Attributes available to this derive:
    #[enum_kind]
}
Expand description

Derive the EnumKind trait and generate a unit kind enum from a data-carrying enum.

This macro generates:

  • Kind enum
  • impl EnumKind for T

§Container attributes

  • #[enum_kind(name = MyKind)]: custom name for the generated kind enum (default: {Enum}Kind)
  • #[enum_kind(attr(...))]: forward attributes to the generated kind enum (repeatable)
  • #[enum_kind(no_default_derive)]: disable the default Debug, Clone, Copy, PartialEq, Eq derives on generated kind enum

§Variant attributes

  • #[enum_kind(rename = Bar)]: rename the kind variant
  • #[enum_kind(attr(...))]: forward attributes to the kind variant (repeatable)

§Example

use enum_helper::EnumKind;

#[derive(EnumKind)]
enum Message {
    Text(String),
    Quit,
}

let msg = Message::Text("hello".into());
assert_eq!(msg.kind(), MessageKind::Text);