Enum rustc_ast::tokenstream::TokenTree
source · [−]pub enum TokenTree {
Token(Token),
Delimited(DelimSpan, DelimToken, TokenStream),
}Expand description
When the main Rust parser encounters a syntax-extension invocation, it parses the arguments to the invocation as a token tree. This is a very loose structure, such that all sorts of different AST fragments can be passed to syntax extensions using a uniform type.
If the syntax extension is an MBE macro, it will attempt to match its
LHS token tree against the provided token tree, and if it finds a
match, will transcribe the RHS token tree, splicing in any captured
macro_parser::matched_nonterminals into the SubstNts it finds.
The RHS of an MBE macro is the only place SubstNts are substituted.
Nothing special happens to misnamed or misplaced SubstNts.
Variants
Token(Token)
A single token.
Delimited(DelimSpan, DelimToken, TokenStream)
A delimited sequence of token trees.
Implementations
sourceimpl TokenTree
impl TokenTree
sourcepub fn eq_unspanned(&self, other: &TokenTree) -> bool
pub fn eq_unspanned(&self, other: &TokenTree) -> bool
Checks if this TokenTree is equal to the other, regardless of span information.
pub fn token(kind: TokenKind, span: Span) -> TokenTree
sourcepub fn open_tt(span: DelimSpan, delim: DelimToken) -> TokenTree
pub fn open_tt(span: DelimSpan, delim: DelimToken) -> TokenTree
Returns the opening delimiter as a token tree.
sourcepub fn close_tt(span: DelimSpan, delim: DelimToken) -> TokenTree
pub fn close_tt(span: DelimSpan, delim: DelimToken) -> TokenTree
Returns the closing delimiter as a token tree.
pub fn uninterpolate(self) -> TokenTree
Trait Implementations
sourceimpl From<TokenTree> for TokenStream
impl From<TokenTree> for TokenStream
sourcefn from(tree: TokenTree) -> TokenStream
fn from(tree: TokenTree) -> TokenStream
Performs the conversion.
sourceimpl From<TokenTree> for TreeAndSpacing
impl From<TokenTree> for TreeAndSpacing
sourcefn from(tree: TokenTree) -> TreeAndSpacing
fn from(tree: TokenTree) -> TreeAndSpacing
Performs the conversion.
sourceimpl FromIterator<TokenTree> for TokenStream
impl FromIterator<TokenTree> for TokenStream
sourcefn from_iter<I: IntoIterator<Item = TokenTree>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = TokenTree>>(iter: I) -> Self
Creates a value from an iterator. Read more
sourceimpl<__CTX> HashStable<__CTX> for TokenTree where
__CTX: HashStableContext,
impl<__CTX> HashStable<__CTX> for TokenTree where
__CTX: HashStableContext,
fn hash_stable(&self, __hcx: &mut __CTX, __hasher: &mut StableHasher)
impl StructuralPartialEq for TokenTree
Auto Trait Implementations
impl !RefUnwindSafe for TokenTree
impl !Send for TokenTree
impl !Sync for TokenTree
impl Unpin for TokenTree
impl !UnwindSafe for TokenTree
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more
Layout
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.
Size: 32 bytes
Size for each variant:
Token: 31 bytesDelimited: 31 bytes