pub trait Codec: Send + Sync {
// Required methods
fn encode<T>(&self, value: &T) -> Result<Vec<u8>, CodecError>
where T: Serialize;
fn decode<T>(&self, data: &[u8]) -> Result<T, CodecError>
where T: DeserializeOwned;
fn content_type(&self) -> &'static str;
}Expand description
Trait for message encoding and decoding
Required Methods§
Sourcefn encode<T>(&self, value: &T) -> Result<Vec<u8>, CodecError>where
T: Serialize,
fn encode<T>(&self, value: &T) -> Result<Vec<u8>, CodecError>where
T: Serialize,
Encode a value to bytes
Sourcefn decode<T>(&self, data: &[u8]) -> Result<T, CodecError>where
T: DeserializeOwned,
fn decode<T>(&self, data: &[u8]) -> Result<T, CodecError>where
T: DeserializeOwned,
Decode bytes to a value
Sourcefn content_type(&self) -> &'static str
fn content_type(&self) -> &'static str
Get the content type for this codec
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.