Format

Trait Format 

Source
pub trait Format {
    type In: ?Sized;
    type Out;
    type Buffer: ToSql + FromSql;
    type SerializeError: Error;
    type DeserializeError: Error;

    // Required methods
    fn sql_type() -> &'static str;
    fn serialize(
        target: &Self::In,
    ) -> Result<Self::Buffer, Self::SerializeError>;
    fn deserialize(
        data: &Self::Buffer,
    ) -> Result<Self::Out, Self::DeserializeError>;
}
Expand description

The trait that tells collections how to serialize and deserialize their types. Serializers are typically built on Serde, but aren’t required to be. For instance, Ipv4Addr can be directly stored and loaded as a SQLite INTEGER using the From Trait, and Parse can be used for types that implement Display and FromStr.

Required Associated Types§

Source

type In: ?Sized

The type that is passed into function calls, for insertion, checking, etc. This type is serialized.

Source

type Out

The type that is returned from function calls. This type is deserialized.

Source

type Buffer: ToSql + FromSql

An owned buffer, for serialization and deserialization. This is not exposed to the user.

Source

type SerializeError: Error

Source

type DeserializeError: Error

Required Methods§

Source

fn sql_type() -> &'static str

The column type. This is not a constant, because you might want to query the SQLite version to select the best type for the version (for instance, selecting ANY for a STRICT table only where it’s available, and BLOB otherwise).

Source

fn serialize(target: &Self::In) -> Result<Self::Buffer, Self::SerializeError>

Serialize a borrowed target into a buffer.

Source

fn deserialize(data: &Self::Buffer) -> Result<Self::Out, Self::DeserializeError>

Deserialize a target from a borrowed buffer.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<Out, In> Format for Parse<Out, In>
where In: ?Sized + ToString, Out: FromStr, <Out as FromStr>::Err: Error,

Source§

impl<Out, In> Format for Raw<Out, In>
where In: ToSql + ?Sized + ToOwned<Owned = Out>, Out: ToSql + FromSql + Clone + Borrow<In>,