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§
Sourcefn content_type(&self) -> ContentType
fn content_type(&self) -> ContentType
Returns the content type for this serializer
Sourcefn content_encoding(&self) -> ContentEncoding
fn content_encoding(&self) -> ContentEncoding
Returns the content encoding for this serializer
Sourcefn serialize<T: Serialize>(&self, value: &T) -> SerializerResult<Vec<u8>>
fn serialize<T: Serialize>(&self, value: &T) -> SerializerResult<Vec<u8>>
Serialize a value to bytes
Sourcefn deserialize<T: DeserializeOwned>(&self, bytes: &[u8]) -> SerializerResult<T>
fn deserialize<T: DeserializeOwned>(&self, bytes: &[u8]) -> SerializerResult<T>
Deserialize bytes to a value
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.