pub trait Serializer {
    type TargetBorrowed: ?Sized;
    type Target: Borrow<Self::TargetBorrowed>;
    type BufferBorrowed: ?Sized + ToSql;
    type Buffer: Borrow<Self::BufferBorrowed> + FromSql;
    type SerializeError: Error;
    type DeserializeError: Error;

    // Required methods
    fn sql_type() -> &'static str;
    fn serialize(
        target: &Self::TargetBorrowed
    ) -> Result<Self::Buffer, Self::SerializeError>;
    fn deserialize(
        data: &Self::BufferBorrowed
    ) -> Result<Self::Target, 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. There are unit tests for exactly this use-case.

Required Associated Types§

source

type TargetBorrowed: ?Sized

A borrowed target, for serialization. This is exposed to the user of the collections in order for them to insert or query the collection.

source

type Target: Borrow<Self::TargetBorrowed>

An owned target, for deserialization. This is exposed to the user in objects returned to them from queries.

source

type BufferBorrowed: ?Sized + ToSql

A borrowed buffer, for deserialization. This is not exposed to the user.

source

type Buffer: Borrow<Self::BufferBorrowed> + FromSql

An owned buffer, for serialization. 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::TargetBorrowed ) -> Result<Self::Buffer, Self::SerializeError>

Serialize a borrowed target into a buffer.

source

fn deserialize( data: &Self::BufferBorrowed ) -> Result<Self::Target, Self::DeserializeError>

Deserialize a target from a borrowed buffer.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<Owned, Borrowed> Serializer for Direct<Owned, Borrowed>
where Borrowed: ToSql + ?Sized + ToOwned<Owned = Owned>, Owned: FromSql + Borrow<Borrowed>,

§

type Target = Owned

§

type TargetBorrowed = Borrowed

§

type Buffer = Owned

§

type BufferBorrowed = Borrowed

§

type SerializeError = Infallible

§

type DeserializeError = Infallible