Skip to main content

mirror_enum

Macro mirror_enum 

Source
macro_rules! mirror_enum {
    (
        $(#[$meta:meta])*
        $vis:vis enum $name:ident from $upstream:path {
            $first:ident,
            $($variant:ident),* $(,)?
        }
    ) => { ... };
}
Expand description

Generates a mirror enum with serde, Display, matches_config, and From impls.

ยงUsage

mirror_enum! {
    pub enum GameMode from pumpkin_plugin_api::player::GameMode {
        Survival,
        Creative,
        Adventure,
        Spectator,
    }
}

This produces:

  • An enum with Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Hash
  • #[serde(rename_all = "PascalCase")]
  • matches_config(&self, allowed: &[Self]) -> bool
  • Display via Debug representation
  • From<upstream> with a catch-all fallback to the first variant