Skip to main content

Discriminant

Derive Macro Discriminant 

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

#[derive(Discriminant)] — auto-implement pub const fn <method>(&self) -> &'static str returning the variant name as a stable case-folded identifier.

§Attributes

  • #[discriminant(method = "kind")] — method name (default "discriminant")
  • #[discriminant(case = "kebab" | "snake" | "lower" | "title")] — variant-name case transformation (default "kebab")
  • #[discriminant(also_display)] — also emit impl Display delegating to the method (writes the variant string to the formatter). Eliminates the boilerplate Display impl that recurs across the substrate for typed enums where Display IS the discriminant.
  • Per-variant #[discriminant(name = "explicit-name")] overrides the auto-derived name (used when the wire format pre-dates the rule).

Compounding: pairs naturally with #[derive(IsVariant)] (predicate methods) and #[derive(TypedDispatcher)] (variant → consumer arm dispatch). All three target the same closed-variant-universe shape the pleme-io substrate uses everywhere.