Serializer

Trait Serializer 

Source
pub trait Serializer: Send + Sync {
    // Required methods
    fn content_type(&self) -> ContentType;
    fn content_encoding(&self) -> ContentEncoding;
    fn serialize<T: Serialize>(&self, value: &T) -> SerializerResult<Vec<u8>>;
    fn deserialize<T: DeserializeOwned>(
        &self,
        bytes: &[u8],
    ) -> SerializerResult<T>;
    fn name(&self) -> &'static str;
}
Expand description

Trait for pluggable serialization formats

Implementors of this trait can serialize and deserialize data to/from bytes, providing their content type and encoding information.

Required Methods§

Source

fn content_type(&self) -> ContentType

Returns the content type for this serializer

Source

fn content_encoding(&self) -> ContentEncoding

Returns the content encoding for this serializer

Source

fn serialize<T: Serialize>(&self, value: &T) -> SerializerResult<Vec<u8>>

Serialize a value to bytes

Source

fn deserialize<T: DeserializeOwned>(&self, bytes: &[u8]) -> SerializerResult<T>

Deserialize bytes to a value

Source

fn name(&self) -> &'static str

Returns the name of this serializer

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§