Struct Lookahead1
struct Lookahead1<'a> { ... }
Support for checking the next token in a stream to decide how to parse.
An important advantage over ParseStream::peek is that here we
automatically construct an appropriate error message based on the token
alternatives that get peeked. If you are producing your own error message,
go ahead and use ParseStream::peek instead.
Use ParseStream::lookahead1 to construct this object.
Consuming tokens from the source stream after constructing a lookahead object does not also advance the lookahead object.
Example
use ;
use ;
// A generic parameter, a single one of the comma-separated elements inside
// angle brackets in:
//
// fn f<T: Clone, 'a, 'b: 'a, const N: usize>() { ... }
//
// On invalid input, lookahead gives us a reasonable error message.
//
// error: expected one of: identifier, lifetime, `const`
// |
// 5 | fn f<!Sized>() {}
// | ^
Implementations
impl<'a> Lookahead1<'a>
fn peek<T: Peek>(self: &Self, token: T) -> boolLooks at the next token in the parse stream to determine whether it matches the requested type of token.
Syntax
Note that this method does not use turbofish syntax. Pass the peek type inside of parentheses.
input.peek(Token![struct])input.peek(Token![==])input.peek(Ident)(does not accept keywords)input.peek(Ident::peek_any)input.peek(Lifetime)input.peek(token::Brace)
fn error(self: Self) -> ErrorTriggers an error at the current position of the parse stream.
The error message will identify all of the expected token types that have been peeked against this lookahead instance.
impl<'a> Freeze for Lookahead1<'a>
impl<'a> RefUnwindSafe for Lookahead1<'a>
impl<'a> Send for Lookahead1<'a>
impl<'a> Sync for Lookahead1<'a>
impl<'a> Unpin for Lookahead1<'a>
impl<'a> UnsafeUnpin for Lookahead1<'a>
impl<'a> UnwindSafe for Lookahead1<'a>
impl<T> Any for Lookahead1<'a>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Lookahead1<'a>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Lookahead1<'a>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> From for Lookahead1<'a>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into for Lookahead1<'a>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Lookahead1<'a>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Lookahead1<'a>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>