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

    // Required method
    fn parse_with_context<BV: BufferView<&'a [u8]>>(
        data: &mut BV,
        context: &mut Self::Context
    ) -> RecordParseResult<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, implementers are advised to make Record a reference into the bytes passed to parse_with_context. Such a reference will need to carry the lifetime 'a, which is the same lifetime that is passed to parse_with_context, and is also the lifetime parameter to this trait.

Required Methods§

source

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

Parses a record with some context.

parse_with_context takes a variable-length data and a context to maintain state.

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

When returning Ok(ParsedRecord::Skipped), it’s the implementer’s responsibility to consume the bytes of the record from data. If this doesn’t happen, then parse_with_context will be called repeatedly on the same data, and the program will be stuck in an infinite loop. If the implementation is unable to determine how many bytes to consume from data in order to skip the record, parse_with_context must return Err.

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

Object Safety§

This trait is not object safe.

Implementors§

source§

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

§

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