pub trait Decoder<T> {
// Required method
fn decode(payload: &[u8]) -> Result<T, DecodeError>;
}Expand description
The decode half of a codec. Separate from Codec because encoding is
?Sized (you can encode a &str) while decoding must produce an owned,
deserializable value. Json, Msgpack, Cbor, and Bson implement both.
A custom codec (Avro, Protobuf, Arrow, or your own framing) implements only
the half it needs.
struct AvroCodec<S>(std::marker::PhantomData<S>);
// impl<S: AvroDeserialize> Decoder<S> for AvroCodec<S> {
// fn decode(payload: &[u8]) -> Result<S, DecodeError> {
// avro::from_avro_bytes(payload).map_err(|e| DecodeError::Decode(e.to_string()))
// }
// }Required Methods§
Sourcefn decode(payload: &[u8]) -> Result<T, DecodeError>
fn decode(payload: &[u8]) -> Result<T, DecodeError>
Decode bytes previously produced by the matching Codec::encode.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl<T: DeserializeOwned> Decoder<T> for Bson
Available on crate feature
bson only.