pub enum TokenTree {
Group(Group),
Literal(Literal),
Punct(Punct),
Ident(IdentToken),
Trivia(Trivia),
// some variants omitted
}Variants§
Implementations§
Source§impl TokenTree
impl TokenTree
Sourcepub fn spelling(&self) -> Option<&str>
pub fn spelling(&self) -> Option<&str>
Examples found in repository?
examples/parse_emit_walkthrough.rs (line 23)
10 fn parse(input: &mut ParseStream) -> Result<Self, TokenParseError> {
11 let Some(token) = input.next_token() else {
12 return Err(TokenParseError::UnexpectedEnd {
13 expected: "identifier",
14 span: Span::detached(),
15 });
16 };
17
18 let span = token.span();
19 match token {
20 TokenTree::Ident(identifier) => Ok(Self(identifier)),
21 token => Err(TokenParseError::UnexpectedToken {
22 expected: "identifier",
23 found: token.spelling().unwrap_or("group or trivia").to_owned(),
24 span,
25 }),
26 }
27 }Trait Implementations§
impl Eq for TokenTree
Source§impl Extend<TokenTree> for TokenStream
impl Extend<TokenTree> for TokenStream
Source§fn extend<T: IntoIterator<Item = TokenTree>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = TokenTree>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl FromIterator<TokenTree> for TokenStream
impl FromIterator<TokenTree> for TokenStream
Source§impl Parse for TokenTree
impl Parse for TokenTree
fn parse(input: &mut ParseStream) -> Result<Self, TokenParseError>
impl StructuralPartialEq for TokenTree
Auto Trait Implementations§
impl Freeze for TokenTree
impl RefUnwindSafe for TokenTree
impl Send for TokenTree
impl Sync for TokenTree
impl Unpin for TokenTree
impl UnsafeUnpin for TokenTree
impl UnwindSafe for TokenTree
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more