Trait Encoder

Source
pub trait Encoder {
    type Error;

    // Required methods
    fn put_slice(&mut self, slice: &[u8]) -> Result<(), Self::Error>;
    fn put_byte(&mut self, byte: u8) -> Result<(), Self::Error>;
}
Expand description

A type that can handle an Encodable type

An encoder is responsible for writing bytes into a buffer or other destination. Encoders are used by encodables to write their data. Thus, encoders must uphold the same properties as encodables.

Required Associated Types§

Source

type Error

The error type that can be returned when encoding a value.

For example, some encoders may return an error if the underlying buffer is full

Required Methods§

Source

fn put_slice(&mut self, slice: &[u8]) -> Result<(), Self::Error>

Copies a slice of bytes into the encoder

§Errors

Implementations of this method should return an error if the underlying encoder fails to write the slice of bytes.

Source

fn put_byte(&mut self, byte: u8) -> Result<(), Self::Error>

Appends a single byte into the encoder, if possible.

§Errors

Implementations of this method should return an error if the underlying encoder fails to write the byte.

Implementations on Foreign Types§

Source§

impl Encoder for &mut [u8]

Source§

type Error = InsufficientSpace

Source§

fn put_slice(&mut self, slice: &[u8]) -> Result<(), Self::Error>

Source§

fn put_byte(&mut self, byte: u8) -> Result<(), Self::Error>

Source§

impl Encoder for ()

Source§

type Error = Infallible

Source§

fn put_slice(&mut self, _: &[u8]) -> Result<(), Self::Error>

Source§

fn put_byte(&mut self, _: u8) -> Result<(), Self::Error>

Source§

impl Encoder for Vec<u8>

Source§

type Error = Infallible

Source§

fn put_slice(&mut self, slice: &[u8]) -> Result<(), Self::Error>

Source§

fn put_byte(&mut self, byte: u8) -> Result<(), Self::Error>

Source§

impl Encoder for BytesMut

Source§

type Error = Infallible

Source§

fn put_slice(&mut self, slice: &[u8]) -> Result<(), Self::Error>

Source§

fn put_byte(&mut self, byte: u8) -> Result<(), Self::Error>

Source§

impl<const SIZE: usize> Encoder for ArrayVec<u8, SIZE>

Source§

type Error = InsufficientSpace

Source§

fn put_slice(&mut self, slice: &[u8]) -> Result<(), Self::Error>

Source§

fn put_byte(&mut self, byte: u8) -> Result<(), Self::Error>

Implementors§