Skip to main content
Requires feature = "derive". See the derives overview for rename_all casings.
#[derive(DuckEnum)] maps a Rust unit enum to a DuckDB ENUM. It generates three impls: From<T> for DuckValue, FromDuckValue for T, and AppendAble for T — so the enum binds, appends, and reads back as a real ENUM (bound by label, which DuckDB casts to the target ENUM).
  • Variants must be unit variants (no fields); at least one is required — otherwise a compile error.
  • Reads accept either an ENUM value or a VARCHAR label.
  • The label is resolved from the variant’s rename → the container rename_all → the Rust variant name.

Attributes

DuckEnum uses the dedicated #[duck_enum(...)] attribute (not #[duck(...)]):
The #[derive(DuckEnum)] macro (attribute #[duck_enum(...)]) is distinct from the runtime DuckEnum value type it maps through — one is a derive, the other is the dictionary-preserving value carried in DuckValue::Enum.

Diesel emission

With better-duck-diesel’s derive feature on, #[derive(DuckEnum)] additionally emits Diesel ToSql / FromSql against better_duck_diesel::sql_types::DuckEnum (routing through the DuckDb backend), so the same type binds and loads through a DuckDbConnection. The deriving crate must then depend on better-duck-diesel — see the Diesel docs. With the feature off, nothing extra is emitted.

See also