pub trait TokenParse: Sized {
type Intermediate;
// Required methods
fn match_(
m_token: Option<&Token>,
span: Span,
) -> Result<Self::Intermediate, ParseErr>;
fn convert(imed: Self::Intermediate, span: Span) -> Result<Self, ParseErr>;
}
Expand description
Components that can be constructed with a single token and require no additional parser state.
This has an advantage over Parse
in that if parsing fails,
the parser is known to not advance its input.
This can be taken advantage of with Parser::match_
,
which only advances if parsing passes.
Required Associated Types§
Sourcetype Intermediate
type Intermediate
An intermediate to hold the match before it is converted to the actual component.
Required Methods§
Sourcefn match_(
m_token: Option<&Token>,
span: Span,
) -> Result<Self::Intermediate, ParseErr>
fn match_( m_token: Option<&Token>, span: Span, ) -> Result<Self::Intermediate, ParseErr>
Tries to match the next token to the given component, if possible.
If successful, this returns some value and the parser advances. If unsuccessful, this returns an error and the parser does not advance.
The value returned is an intermediate value which is later converted to the desired component.
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.