Trait sqlite_collections::serializer::Serializer
source · 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§
sourcetype TargetBorrowed: ?Sized
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.
sourcetype Target: Borrow<Self::TargetBorrowed>
type Target: Borrow<Self::TargetBorrowed>
An owned target, for deserialization. This is exposed to the user in objects returned to them from queries.
sourcetype BufferBorrowed: ?Sized + ToSql
type BufferBorrowed: ?Sized + ToSql
A borrowed buffer, for deserialization. This is not exposed to the user.
sourcetype Buffer: Borrow<Self::BufferBorrowed> + FromSql
type Buffer: Borrow<Self::BufferBorrowed> + FromSql
An owned buffer, for serialization. This is not exposed to the user.
type SerializeError: Error
type DeserializeError: Error
Required Methods§
sourcefn sql_type() -> &'static str
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).
sourcefn serialize(
target: &Self::TargetBorrowed
) -> Result<Self::Buffer, Self::SerializeError>
fn serialize( target: &Self::TargetBorrowed ) -> Result<Self::Buffer, Self::SerializeError>
Serialize a borrowed target into a buffer.
sourcefn deserialize(
data: &Self::BufferBorrowed
) -> Result<Self::Target, Self::DeserializeError>
fn deserialize( data: &Self::BufferBorrowed ) -> Result<Self::Target, Self::DeserializeError>
Deserialize a target from a borrowed buffer.