Trait async_codec::Encode [−][src]
pub trait Encode {
type Item;
type Error;
fn encode(
&mut self,
item: &Self::Item,
buf: &mut [u8]
) -> EncodeResult<Self::Error>;
fn reset(&mut self) { ... }
}
Expand description
Trait for things that can be encoded to a byte buffer
Associated Types
Required methods
Encode self
and place the encoded representation in the provided
buffer.
Returns either a usize
representing the length of the buffer used, or
an EncodeResult::Overflow containing either the minimum required
buffer length, or the error arising from the serialization itself.
Types implementing Encode
may employ internal buffering to make
repeated calls to encode
with the same object cheaper in the event of
an overflow error. If buffering is employed, the internal buffer should
be cleared after the item has been successfully copied into the provided
one.
Provided methods
Signal the encoder that it should discard its internal buffer if it has one.
This may be needed if the encoder caches the result of encoding an
Item
between an Overflow
result and the Ok
once the caller has
provided an adequate buffer. Because the caller may not support a
growable buffer, encoders cannot rely on being able to discard thier
buffer when returning Ok
.