pub trait Peek {
// Required methods
fn peek(cursor: Cursor<'_>) -> Result<bool>;
fn display() -> &'static str;
// Provided method
fn peek2(cursor: Cursor<'_>) -> Result<bool> { ... }
}
Expand description
A trait for types which be used to “peek” to see if they’re the next token
in an input stream of Parser
.
Often when implementing Parse
you’ll need to query what the next token
in the stream is to figure out what to parse next. This Peek
trait
defines the set of types that can be tested whether they’re the next token
in the input stream.
Implementations of Peek
should only be present on types that consume
exactly one token (not zero, not more, exactly one). Types implementing
Peek
should also typically implement Parse
should also typically
implement Parse
.
See the documentation of Parser::peek
for example usage.
Required Methods§
Provided Methods§
Object Safety§
This trait is not object safe.