Skip to main content

Decoder

Trait Decoder 

Source
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§

Source

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§

Source§

impl<T: DeserializeOwned> Decoder<T> for Bson

Available on crate feature bson only.
Source§

impl<T: DeserializeOwned> Decoder<T> for Cbor

Source§

impl<T: DeserializeOwned> Decoder<T> for Json

Source§

impl<T: DeserializeOwned> Decoder<T> for Msgpack