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.

Source§

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.

1.29.0 · Source§

1.29.0 · Source§

Prints token tree in a form convenient for debugging.

1.29.0 · Source§

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::Groups 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.

1.30.0 · Source§

Source§

Extends a collection with the contents of an iterator. Read more

Source§

🔬This is a nightly-only experimental API. (extend_one #72631)

Extends a collection with exactly one element.

Source§

🔬This is a nightly-only experimental API. (extend_one #72631)

Reserves capacity in a collection for the given number of additional elements. Read more

1.29.0 · Source§

Source§

Converts to this type from the input type.

1.29.0 · Source§

Source§

Converts to this type from the input type.

1.29.0 · Source§

Source§

Converts to this type from the input type.

1.29.0 · Source§

Source§

Converts to this type from the input type.

1.29.0 · Source§

Creates a token stream containing a single token tree.

Source§

Converts to this type from the input type.

1.29.0 · Source§

Collects a number of token trees into a single stream.

Source§

Source§

🔬This is a nightly-only experimental API. (proc_macro_totokens #130977)

Write self to the given TokenStream. Read more

Source§

🔬This is a nightly-only experimental API. (proc_macro_totokens #130977)

Convert self directly into a TokenStream object. Read more

Source§

🔬This is a nightly-only experimental API. (proc_macro_totokens #130977)

Convert self directly into a TokenStream object. Read more

1.29.0 · Source§

1.29.0 · Source§

§

§

§

§