Trait packet::records::options::OptionsImpl

source ·
pub trait OptionsImpl: OptionParseLayout {
    type Option<'a>;

    // Required method
    fn parse<'a>(
        kind: Self::KindLenField,
        data: &'a [u8],
    ) -> Result<Option<Self::Option<'a>>, Self::Error>;
}
Expand description

An implementation of an options parser.

OptionsImpl provides functions to parse fixed- and variable-length options. It is required in order to construct an Options.

Required Associated Types§

source

type Option<'a>

The type of an option; the output from the parse function.

For long or variable-length data, implementers are advised to make Option a reference into the bytes passed to parse. Such a reference will need to carry the lifetime 'a, which is the same lifetime that is passed to parse, and is also the lifetime parameter to this trait.

Required Methods§

source

fn parse<'a>( kind: Self::KindLenField, data: &'a [u8], ) -> Result<Option<Self::Option<'a>>, Self::Error>

Parses an option.

parse takes a kind byte and variable-length data and returns Ok(Some(o)) if the option successfully parsed as o, Ok(None) if the kind byte was unrecognized, and Err(err) if the kind byte was recognized but data was malformed for that option kind.

parse is allowed to not recognize certain option kinds, as the length field can still be used to safely skip over them, but it must recognize all single-byte options (if it didn’t, a single-byte option would be spuriously interpreted as a multi-byte option, and the first byte of the next option byte would be spuriously interpreted as the option’s length byte).

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

Object Safety§

This trait is not object safe.

Implementors§