Skip to main content

DecodeIter

Trait DecodeIter 

Source
pub trait DecodeIter<'a>: Sized {
    type Error: From<Incomplete>;

    const WIRE_SIZE: Option<usize> = None;

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

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

RX-side: decode a sequence of same-typed elements from a buffer. Implement this only for protocols that have repeated elements (e.g. a UDS DTC record list).

Provided Associated Constants§

Source

const WIRE_SIZE: Option<usize> = None

Wire size of one element, when fixed at compile time (must be non-zero if Some). Enables DecodeIterator::remaining_len for fixed-stride record streams. Default: None (variable-width).

Required Associated Types§

Source

type Error: From<Incomplete>

Per-implementation error; constructible from Incomplete so the fixed-width leaf read helpers lift through ?. As with Decode::Error, the variable-width helpers return ReadUintError and need their own From impl.

Required Methods§

Source

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

Decode the next element from the front of buf.

Returns Ok(Some((value, rest))) for an element, Ok(None) for a clean end (buffer empty / no more elements), or Err(_) for malformed input.

Convention — check for the clean end BEFORE attempting to decode an element. Exhaustion must be Ok(None), never Err(Incomplete { available: 0, .. }): a decode_next that delegates straight to a Decode impl will wrongly turn an empty buffer into an error. The reference shape is:

if buf.is_empty() { return Ok(None); }
Decode::decode(buf).map(Some)

A partial element after a good start IS a real error — surfacing it (rather than silently stopping) is deliberate; the adapter fuses after the first Err. Consumers migrating from silent-truncation iterators should treat the newly surfaced error as the correct behavior and keep any pre-validated fast path on a separate infallible iterator.

§Errors

Self::Error if the next element is malformed.

Provided Methods§

Source

fn iter(buf: &'a [u8]) -> DecodeIterator<'a, Self>

Adapter: iterate all elements, yielding Result<Self, Self::Error>. Stops at the first Ok(None) or Err(_).

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§