Trait Decodable

Source
pub trait Decodable: Sized {
    type Error;

    // Required method
    fn decode(buf: &[u8]) -> (Result<Self, Self::Error>, usize);

    // Provided method
    fn decode_multiple(
        buf: &[u8],
        max: Option<usize>,
    ) -> (Vec<Result<Self, Self::Error>>, usize) { ... }
}
Expand description

A decodable type can be created from a byte buffer. The type returned is separate (copied) from the buffer once decoded.

Required Associated Types§

Required Methods§

Source

fn decode(buf: &[u8]) -> (Result<Self, Self::Error>, usize)

Decodes into a new object or an error, and the number of bytes that the decoding consumed. Should attempt to consume the entire item from the buffer in the case of an error. If the item end cannot be determined, return an error and consume the entirety of the bufer (buf.len())

Provided Methods§

Source

fn decode_multiple( buf: &[u8], max: Option<usize>, ) -> (Vec<Result<Self, Self::Error>>, usize)

Tries to decode a collection of this object concatenated in a buffer. Returns a vector of items (or errors) and the number of bytes consumed to decode them. Continues to decode items until the buffer is consumed or the max items. If None, will decode the entire buffer.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§