Skip to main content

EnumMapping

Trait EnumMapping 

Source
pub trait EnumMapping<DB: Backend> {
    // Required methods
    fn map_to_database_value<'b>(
        output: &mut Output<'b, '_, DB>,
        variant: &'static EnumVariant,
    ) -> Result;
    fn map_from_database_value(
        raw: DB::RawValue<'_>,
        type_name: &'static str,
        variants: &'static [EnumVariant],
    ) -> Result<usize>;
}
Available on crate feature i-implement-a-third-party-backend-and-opt-into-breaking-changes only.
Expand description

A helper trait to describe mapping an enum between rust values and database values

This is implemented for different mapping strategies, some of them might be database dependent, while others might be independent

Required Methods§

Source

fn map_to_database_value<'b>( output: &mut Output<'b, '_, DB>, variant: &'static EnumVariant, ) -> Result

Map an enum variant to the database representation

Source

fn map_from_database_value( raw: DB::RawValue<'_>, type_name: &'static str, variants: &'static [EnumVariant], ) -> Result<usize>

Construct an enum variant from the database representation

This is expected to return the index of the variant in the variants array

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl EnumMapping<Mysql> for EnumTypeMapping

Available on crate feature mysql_backend only.
Source§

impl EnumMapping<Pg> for EnumTypeMapping

Available on crate feature postgres_backend only.
Source§

impl<DB> EnumMapping<DB> for StringMapping
where DB: Backend, for<'a> &'a str: FromSqlRef<'a, Text, DB>, &'static str: ToSql<Text, DB>,

Source§

impl<T, ST, DB> EnumMapping<DB> for IntMapping<T, ST>
where for<'a> DB: Backend<BindCollector<'a> = RawBytesBindCollector<DB>>, T: ToSql<ST, DB> + FromSql<ST, DB>, i128: TryInto<T, Error: Display> + TryFrom<T, Error: Display>,

Source§

impl<T, ST> EnumMapping<Sqlite> for IntMapping<T, ST>
where T: ToSql<ST, Sqlite> + FromSql<ST, Sqlite>, for<'a> SqliteBindValue<'a>: From<T>, i128: TryInto<T, Error: Display> + TryFrom<T, Error: Display>,

Available on crate feature __sqlite-shared only.