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§
Required Methods§
Sourcefn encode(
&self,
item: Self::Item,
dst: &mut BytePages,
) -> Result<(), Self::Error>
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".