Skip to main content

Encoder

Trait Encoder 

Source
pub trait Encoder<Item, B: IoBufMut> {
    type Error: From<Error>;

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

Trait for types that encode values into bytes.

Required Associated Types§

Source

type Error: From<Error>

The error type that can be returned during encoding operations.

Required Methods§

Source

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

Encodes an item into bytes.

The buf is guaranteed to have 0 initialized bytes (buf_len() == 0). If the function is returned successfully, all initialized bytes will be treated as valid content to be transmitted.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<B: IoBufMut> Encoder<Bytes, B> for BytesCodec

Available on crate feature bytes only.