Skip to main content

Crate pyenum

Crate pyenum 

Source
Expand description

§pyenum

Expose Rust enum types to Python as genuine enum.Enum subclasses via PyO3 — #[derive(PyEnum)], functional-API class construction, a per-interpreter cache, and IntoPyObject / FromPyObject conversion plumbing generated by the derive.

§Scope

  • Unit-variant enums only; tuple / struct / generic / lifetime-parameterised enums are rejected at compile time.
  • Five Python enum bases are selectable: Enum (default), IntEnum, StrEnum, Flag, IntFlag.
  • Rust variant names are passed through unchanged (Python member name == Rust identifier).
  • The Python class is constructed exactly once per interpreter and cached via pyo3::sync::PyOnceLock.
  • PyO3 0.28, CPython 3.11+.
  • Free-threaded (--disable-gil) Python, module reload, and sub-interpreter finalisation are out of scope.

Structs§

PyEnumSpec
Static metadata emitted by #[derive(PyEnum)] for each derived enum.

Enums§

PyEnumBase
Python enum base type selector.
VariantLiteral
A single variant’s declared value, ready to be materialised into a Python-side (name, value) tuple for the functional enum.* constructor.

Traits§

PyEnumTrait
Bridge between a #[derive(PyEnum)] Rust type and its cached Python class.
PyModuleExt
Extension-method form of add_enumm.add_enum::<T>()? inside a #[pymodule] is the idiomatic call site.

Functions§

add_enum
Register the Python class for T onto module under T::SPEC.name.

Derive Macros§

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