Skip to main content

Decode

Trait Decode 

Source
pub trait Decode<'a>: Sized {
    type Error: From<Incomplete> + From<TrailingBytes>;

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

    // Provided method
    fn decode_exact(buf: &'a [u8]) -> Result<Self, Self::Error> { ... }
}
Expand description

RX-side: zero-copy decode borrowing from buf. The value is valid only as long as buf lives.

Required Associated Types§

Source

type Error: From<Incomplete> + From<TrailingBytes>

Per-implementation error; constructible from Incomplete and TrailingBytes so the fixed-width leaf read helpers (read_u8, read_u16_be, read_array, …) and the decode_exact default lift through ?.

The variable-width helpers read_be_uint and read_be_uint_into return ReadUintError instead; to call them inside decode with ?, additionally implement From<ReadUintError> for your error (match both arms — see the error pattern in MIGRATION.md).

Required Methods§

Source

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

Decode from the FRONT of buf; return (value, unconsumed_remainder).

§Errors

Self::Error if the input is malformed or too short.

Provided Methods§

Source

fn decode_exact(buf: &'a [u8]) -> Result<Self, Self::Error>

Decode requiring the ENTIRE buffer to be consumed. Use this at a message boundary where the length is already known.

Do NOT use it where a buffer may legally hold more than one message (e.g. a multi-message datagram): there, trailing bytes are the next message, not an error — use decode and thread the remainder.

§Errors

TrailingBytes (via Self::Error) if bytes remain, plus anything decode can return.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<'a> Decode<'a> for EntryView<'a>

Source§

impl<'a> Decode<'a> for HeaderView<'a>

Source§

impl<'a> Decode<'a> for MessageView<'a>

Source§

impl<'a> Decode<'a> for OptionView<'a>

Source§

impl<'a> Decode<'a> for SdBody<'a>