Skip to main content

DbEnum

Trait DbEnum 

Source
pub trait DbEnum: Sized {
    const ENUM_NAME: &'static str;
    const VARIANTS: &'static [&'static str];
    const SQL_TYPE: SqlType = _;

    // Required methods
    fn as_db_str(&self) -> &'static str;
    fn from_db_str(value: &str) -> Result<Self>;
}
Expand description

A Rust enum mapped to a fixed set of stored text values.

Required Associated Constants§

Source

const ENUM_NAME: &'static str

The enum’s name, used as the type/constraint name in generated DDL.

Source

const VARIANTS: &'static [&'static str]

Every allowed stored value, in declaration order.

Provided Associated Constants§

Source

const SQL_TYPE: SqlType = _

The abstract column type for this enum.

Used by the Model derive (via #[field(db_enum)]) to record the column’s type, including the variant list the DDL renderer constrains against.

Required Methods§

Source

fn as_db_str(&self) -> &'static str

Returns this value’s stored text form.

Source

fn from_db_str(value: &str) -> Result<Self>

Parses a stored text value back into the enum.

Returns a conversion error when the value is not one of VARIANTS.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§