Skip to main content

EnumIs

Derive Macro EnumIs 

Source
#[derive(EnumIs)]
Expand description

Derives helper methods to check if an enum instance matches a specific variant.

For every variant VariantName, this macro implements a const method named is_<variant_name>(&self) -> bool using snake_case naming.

§Compatibility & Limitations

  • Works on enum types only.
  • Supports all enum variant types: unit variants (e.g. Quit), tuple variants (e.g. Write(String)), and struct variants (e.g. Move { x: i32, y: i32 }).

§Feature Flags

If the impl-enuminfo feature is enabled, this macro additionally implements the enuminfo::EnumIs marker trait for the enum.

§Example

use enuminfo_macros::EnumIs;

#[derive(EnumIs)]
enum Message {
    Quit,
    Move { x: i32, y: i32 },
    Write(String),
}

let msg = Message::Move { x: 10, y: 20 };
assert!(msg.is_move());
assert!(!msg.is_quit());
assert!(!msg.is_write());