Skip to main content

PyEnum

Derive Macro PyEnum 

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

Derive a pyenum::PyEnum implementation for a unit-variant Rust enum.

Enum-level attributes (all optional):

  • #[pyenum(base = "Enum" | "IntEnum" | "StrEnum" | "Flag" | "IntFlag")] — select the Python base class. Defaults to "Enum".
  • #[pyenum(name = "...")] — override the Python class name. Defaults to the Rust enum identifier.

Variant-level attributes (all optional, mutually exclusive with a Rust discriminant on the same variant):

  • #[pyenum(value = "...")] — explicit Python string value. Only valid when the enum base is StrEnum or Enum. Without this attribute (and without a Rust discriminant), StrEnum variants default to Python’s auto() semantics, which lowercase the variant name.