Skip to main content

Decoder

Trait Decoder 

Source
pub trait Decoder {
    type Item;
    type Error: From<Error>;

    // Required method
    fn decode(
        &mut self,
        src: &mut BytesMut,
    ) -> Result<Option<Self::Item>, Self::Error>;

    // Provided method
    fn decode_eof(
        &mut self,
        src: &mut BytesMut,
    ) -> Result<Option<Self::Item>, Self::Error> { ... }
}
Expand description

Decoding of frames via buffers, for use with FramedRead.

Required Associated Types§

Source

type Item

The type of items returned by decode

Source

type Error: From<Error>

The type of decoding errors.

Required Methods§

Source

fn decode( &mut self, src: &mut BytesMut, ) -> Result<Option<Self::Item>, Self::Error>

Decode an item from the src BytesMut into an item

Provided Methods§

Source

fn decode_eof( &mut self, src: &mut BytesMut, ) -> Result<Option<Self::Item>, Self::Error>

Called when the input stream reaches EOF, signaling a last attempt to decode

§Notes

The default implementation of this method invokes the Decoder::decode method.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Decoder for BytesCodec

Source§

impl Decoder for LengthCodec

Source§

impl Decoder for LinesCodec

Source§

impl<Enc, Dec> Decoder for CborCodec<Enc, Dec>
where for<'de> Dec: Deserialize<'de> + 'static, for<'de> Enc: Serialize + 'static,

Decoder impl parses cbor objects from bytes

Source§

impl<Enc, Dec> Decoder for JsonCodec<Enc, Dec>
where for<'de> Dec: Deserialize<'de> + 'static, for<'de> Enc: Serialize + 'static,

Decoder impl parses json objects from bytes