pub trait Parse<Ref>: Sized {
// Required methods
fn parse(parser: &mut Parser<Ref>) -> Result<Self, ParseError>;
fn skip(parser: &mut Parser<Ref>) -> Result<(), ParseError>;
}
Expand description
A type that can extract a value from a parser.
The trait is a companion to Parser<Ref>
: it allows a type to use a
parser to create a value of itself. Because types may be generic over
octets types, the trait is generic over the octets reference of the
parser in question. Implementations should use minimal trait bounds
matching the parser methods they use.
For types that are generic over an octets sequence, the reference type
should be tied to the type’s own type argument. This will avoid having
to provide type annotations when simply calling Parse::parse
for the
type. Typically this will happen via OctetsRef::Range
. For instance,
a type Foo<Octets>
should provide:
impl<Ref: OctetsRef> Parse<Ref> for Foo<Ref::Range> {
// etc.
}
Required Methods§
sourcefn parse(parser: &mut Parser<Ref>) -> Result<Self, ParseError>
fn parse(parser: &mut Parser<Ref>) -> Result<Self, ParseError>
Extracts a value from the beginning of parser
.
If parsing fails and an error is returned, the parser’s position should be considered to be undefined. If it is supposed to be reused in this case, you should store the position before attempting to parse and seek to that position again before continuing.