Enum proc_macro::TokenTree
1.29.0 · source · pub enum TokenTree {
Group(Group),
Ident(Ident),
Punct(Punct),
Literal(Literal),
}
Expand description
A single token or a delimited sequence of token trees (e.g., [1, (), ..]
).
Variants§
Group(Group)
A token stream surrounded by bracket delimiters.
Ident(Ident)
An identifier.
Punct(Punct)
A single punctuation character (+
, ,
, $
, etc.).
Literal(Literal)
A literal character ('a'
), string ("hello"
), number (2.3
), etc.
Implementations§
Trait Implementations§
source§impl Display for TokenTree
impl Display for TokenTree
Prints the token tree as a string that is supposed to be losslessly convertible back
into the same token tree (modulo spans), except for possibly TokenTree::Group
s
with Delimiter::None
delimiters and negative numeric literals.
Note: the exact form of the output is subject to change, e.g. there might
be changes in the whitespace used between tokens. Therefore, you should
not do any kind of simple substring matching on the output string (as
produced by to_string
) to implement a proc macro, because that matching
might stop working if such changes happen. Instead, you should work at the
TokenTree
level, e.g. matching against TokenTree::Ident
,
TokenTree::Punct
, or TokenTree::Literal
.
1.30.0 · source§impl Extend<TokenTree> for TokenStream
impl Extend<TokenTree> for TokenStream
source§fn extend<I: IntoIterator<Item = TokenTree>>(&mut self, trees: I)
fn extend<I: IntoIterator<Item = TokenTree>>(&mut self, trees: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
#72631)source§impl From<TokenTree> for TokenStream
impl From<TokenTree> for TokenStream
Creates a token stream containing a single token tree.
source§fn from(tree: TokenTree) -> TokenStream
fn from(tree: TokenTree) -> TokenStream
source§impl FromIterator<TokenTree> for TokenStream
impl FromIterator<TokenTree> for TokenStream
Collects a number of token trees into a single stream.