pub trait Encoding: 'static {
// Required methods
fn content_type() -> &'static str;
fn stream_content_type() -> &'static str;
fn encode(data: impl Serialize, buf: &mut Vec<u8>) -> Option<usize>;
fn decode<O: DeserializeOwned>(bytes: Bytes) -> Option<O>;
// Provided method
fn to_bytes(data: impl Serialize) -> Option<Bytes> { ... }
}Expand description
A trait for encoding and decoding data.
This takes an owned self to make it easier for zero-copy encodings.
Required Methods§
fn content_type() -> &'static str
fn stream_content_type() -> &'static str
fn encode(data: impl Serialize, buf: &mut Vec<u8>) -> Option<usize>
fn decode<O: DeserializeOwned>(bytes: Bytes) -> Option<O>
Provided Methods§
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.