TokenTree in proc_macro - Rust (original) (raw)
Enum 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, (), ..]
).
§1.29.0
A token stream surrounded by bracket delimiters.
§1.29.0
An identifier.
§1.29.0
A single punctuation character (+
, ,
, $
, etc.).
§1.29.0
A literal character ('a'
), string ("hello"
), number (2.3
), etc.
1.29.0 · Source
Returns the span of this tree, delegating to the span
method of the contained token or a delimited stream.
1.29.0 · Source
Configures the span for only this token.
Note that if this token is a Group
then this method will not configure the span of each of the internal tokens, this will simply delegate to the set_span
method of each variant.
Prints token tree in a form convenient for debugging.
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 theTokenTree
level, e.g. matching against TokenTree::Ident
,TokenTree::Punct
, or TokenTree::Literal
.
Extends a collection with the contents of an iterator. Read more
🔬This is a nightly-only experimental API. (extend_one
#72631)
Extends a collection with exactly one element.
🔬This is a nightly-only experimental API. (extend_one
#72631)
Reserves capacity in a collection for the given number of additional elements. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Creates a token stream containing a single token tree.
Converts to this type from the input type.
Collects a number of token trees into a single stream.
🔬This is a nightly-only experimental API. (proc_macro_totokens
#130977)
Write self
to the given TokenStream
. Read more
🔬This is a nightly-only experimental API. (proc_macro_totokens
#130977)
Convert self
directly into a TokenStream
object. Read more
🔬This is a nightly-only experimental API. (proc_macro_totokens
#130977)
Convert self
directly into a TokenStream
object. Read more