ppp_packet::records

Trait RecordsImpl

Source
pub trait RecordsImpl<'a>: RecordsImplLayout {
    type Record;

    // Required method
    fn parse_with_context<BV: BufferView<&'a [u8]>>(
        data: &mut BV,
        context: &mut Self::Context,
    ) -> Result<Option<Option<Self::Record>>, Self::Error>;
}
Expand description

An implementation of a records parser.

RecordsImpl provides functions to parse sequential records. It is required in order to construct a Records or RecordsIter.

Required Associated Types§

Source

type Record

The type of a single record; the output from the parse_with_context function.

For long or variable-length data, the user is advised to make Record a reference into the bytes passed to parse_with_context. This is achievable because of the lifetime parameter to this trait.

Required Methods§

Source

fn parse_with_context<BV: BufferView<&'a [u8]>>( data: &mut BV, context: &mut Self::Context, ) -> Result<Option<Option<Self::Record>>, Self::Error>

Parse a record with some context.

parse_with_context takes a variable-length data and a context to maintain state, and returns Ok(Some(Some(o))) if the the record is successfully parsed as o, Ok(Some(None)) if data is not malformed but the implementer can’t extract a concrete object (e.g. record is an unimplemented enumeration, but we can still safely “skip” it), Ok(None) if parse_with_context is unable to parse more records, and Err(err) if the data was malformed for the attempted record parsing.

data MAY be empty. It is up to the implementer to handle an exhausted data.

When returning Ok(Some(None)) it’s the implementer’s responsibility to nonetheless skip the record (which may not be possible for some implementations, in which case it should return an Err).

parse_with_context must be deterministic, or else Records::parse_with_context cannot guarantee that future iterations will not produce errors (and panic).

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§

Source§

impl<'a, O> RecordsImpl<'a> for OptionsImplBridge<O>
where O: OptionsImpl<'a>,

Source§

type Record = <O as OptionsImpl<'a>>::Option

Source§

impl<'a, O> RecordsImpl<'a> for LimitedRecordsImplBridge<O>
where O: LimitedRecordsImpl<'a>,