Skip to main content

ValueCodec

Trait ValueCodec 

Source
pub trait ValueCodec<T>: 'static {
    const SQL_TYPE: SqlType;

    // Required methods
    fn to_sqlite_value(v: &T) -> Value;
    fn from_sqlite_value(v: Value) -> Result<T, DbError>;
}
Expand description

A named alternative representation for T, serde’s #[serde(with = …)] idiom. Implement on a unit struct; select it per field with #[model(with = …)].

Required Associated Constants§

Required Methods§

Source

fn to_sqlite_value(v: &T) -> Value

Source

fn from_sqlite_value(v: Value) -> Result<T, DbError>

Decode the stored value.

§Errors

Returns a decoding error when v is not a value this codec stores.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl<T> ValueCodec<T> for Json
where T: Serialize + DeserializeOwned + 'static,

Source§

const SQL_TYPE: SqlType = SqlType::Text