Trait ruserf_types::Encodable

source ·
pub trait Encodable: Send + Sync {
    type Error: Error + Send + Sync + 'static;

    // Required methods
    fn encode(&self, dst: &mut [u8]) -> Result<usize, Self::Error>;
    fn encoded_len(&self) -> usize;

    // Provided methods
    fn encode_to_vec(&self) -> Result<Vec<u8>, Self::Error> { ... }
    fn encode_to_writer<W>(&self, writer: &mut W) -> Result<usize, Error>
       where W: Write { ... }
    fn encode_to_async_writer<W>(
        &self,
        writer: &mut W
    ) -> impl Future<Output = Result<usize, Error>> + Send
       where W: AsyncWrite + Send + Unpin { ... }
}
Expand description

The type can transform its representation to byte form.

Required Associated Types§

source

type Error: Error + Send + Sync + 'static

The error type returned when encoding or decoding fails.

Required Methods§

source

fn encode(&self, dst: &mut [u8]) -> Result<usize, Self::Error>

Encodes the value into the given buffer for transmission.

Returns the number of bytes written to the buffer.

source

fn encoded_len(&self) -> usize

Returns the encoded length of the value. This is used to pre-allocate a buffer for encoding.

Provided Methods§

source

fn encode_to_vec(&self) -> Result<Vec<u8>, Self::Error>

Encodes the value into a vec for transmission.

source

fn encode_to_writer<W>(&self, writer: &mut W) -> Result<usize, Error>
where W: Write,

Encodes the value into the given writer for transmission.

source

fn encode_to_async_writer<W>( &self, writer: &mut W ) -> impl Future<Output = Result<usize, Error>> + Send
where W: AsyncWrite + Send + Unpin,

Encodes the value into the given async writer for transmission.

Object Safety§

This trait is not object safe.

Implementors§