mool 0.2.0

A source-first Rust database toolkit for typed SQL queries, migrations, and model metadata
Documentation
//! Public trait implemented by `#[derive(SqlEnum)]`.

use crate::Dialect;

use super::{SqlEnumError, SqlEnumStorage};

/// Maps a Rust enum to a SQL column representation.
///
/// Implementations are generated by `#[derive(SqlEnum)]`. The trait exposes
/// stable metadata for schema generation and label decoding; SQLx bind/scan
/// compatibility is generated separately by the derive macro.
pub trait SqlEnum: Sized + Copy + 'static {
    /// SQL enum type name.
    const SQL_NAME: &'static str;
    /// Storage representation selected for this enum.
    const SQL_STORAGE: SqlEnumStorage;
    /// Text labels for all variants in declaration order.
    const SQL_VALUES: &'static [&'static str];

    /// Returns the SQL text label for this value.
    fn as_sql_str(self) -> &'static str;

    /// Converts a SQL text label into this enum.
    fn try_from_sql_str(value: &str) -> Result<Self, SqlEnumError>;

    /// Returns the SQL column type for schema metadata.
    fn sql_column_type(dialect: Dialect) -> String;

    /// Returns a check expression for text or integer-backed storage.
    fn sql_check_expr(column: &str, dialect: Dialect) -> Option<String>;
}