pub trait Parse<Ref>: Sized {
    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

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.

Skips over a value of this type at the beginning of parser.

This function is the same as parse but doesn’t return the result. It can be used to check if the content of parser is correct or to skip over unneeded parts of the parser.

Implementations on Foreign Types

Implementors