Struct End
pub struct End;
Pseudo-token used for peeking the end of a parse stream.
This type is only useful as an argument to one of the following functions:
- [
ParseStream::peek][crate::parse::ParseBuffer::peek] - [
ParseStream::peek2][crate::parse::ParseBuffer::peek2] - [
ParseStream::peek3][crate::parse::ParseBuffer::peek3] Lookahead1::peek
The peek will return true if there are no remaining tokens after that
point in the parse stream.
Example
Suppose we are parsing attributes containing core::fmt inspired formatting arguments:
#[fmt("simple example")]#[fmt("interpolation e{}ample", self.x)]#[fmt("interpolation e{x}ample")]
and we want to recognize the cases where no interpolation occurs so that more efficient code can be generated.
The following implementation uses input.peek(Token![,]) && input.peek2(End) to recognize the case of a trailing comma without
consuming the comma from the parse stream, because if it isn't a trailing
comma, that same comma needs to be parsed as part of args.
use TokenStream;
use quote;
use ;
use ;
Implementing this parsing logic without peek2(End) is more clumsy because
we'd need a parse stream actually advanced past the comma before being able
to find out whether there is anything after it. It would look something
like:
# use TokenStream;
# use ;
# use Token;
#
#
or:
# use TokenStream;
# use ;
# use Token;
#
#
Trait Implementations
impl Clone for End
fn clone(&self) -> Self
impl Copy for End
impl Peek for End
Auto Trait Implementations
impl Freeze for End
impl RefUnwindSafe for End
impl Send for End
impl Sync for End
impl Unpin for End
impl UnsafeUnpin for End
impl UnwindSafe for End
Blanket Implementations
impl<T> Any for End
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for End
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for End
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for End
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for End
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for End
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T> Token for End
where
T: CustomToken,
fn peek(cursor: Cursor<'_>) -> boolfn display() -> &'static str
impl<T, U> Into<U> for End
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for End
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for End
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>