Skip to main content

Encoder

Trait Encoder 

pub trait Encoder<Item, B>
where B: IoBufMut,
{ type Error: From<Error>; // Required method fn encode(&mut self, item: Item, buf: &mut B) -> Result<(), Self::Error>; }
Available on crate feature io only.
Expand description

Trait for types that encode values into bytes.

Required Associated Types§

type Error: From<Error>

The error type that can be returned during encoding operations.

Required Methods§

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§

§

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

§

type Error = Error

§

impl<T, B> Encoder<T, B> for SerdeJsonCodec
where T: Serialize, B: IoBufMut,