Skip to main content

Encoder

Trait Encoder 

Source
pub trait Encoder {
    type Item;
    type Error: Debug;

    // Required method
    fn encode(
        &self,
        item: Self::Item,
        dst: &mut BytePages,
    ) -> Result<(), Self::Error>;
}
Expand description

Serializes frames into bytes.

Required Associated Types§

Source

type Item

The type of frames consumed by the encoder.

Source

type Error: Debug

The type of encoding errors.

Required Methods§

Source

fn encode( &self, item: Self::Item, dst: &mut BytePages, ) -> Result<(), Self::Error>

Encodes a frame and appends it to dst.

dst is the write buffer, a list of pages. BytePages::append adds a Bytes value as a page of its own without copying it, while BytePages::extend_from_slice and the BufMut methods copy into the pages.

Output written to dst is not rolled back when this returns an error, it is sent like any other output. Validate the frame before writing it, so that an error does not leave a partial frame behind.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<T> Encoder for Rc<T>
where T: Encoder,

Source§

type Item = <T as Encoder>::Item

Source§

type Error = <T as Encoder>::Error

Source§

fn encode( &self, item: Self::Item, dst: &mut BytePages, ) -> Result<(), Self::Error>

Implementors§