Struct rustc_ast::tokenstream::TokenStream
source · Expand description
A TokenStream
is an abstract sequence of tokens, organized into TokenTree
s.
The goal is for procedural macros to work with TokenStream
s and TokenTree
s
instead of a representation of the abstract syntax tree.
Today’s TokenTree
s can still contain AST via token::Interpolated
for
backwards compatibility.
Tuple Fields§
§0: Lrc<Vec<TokenTree>>
Implementations§
source§impl TokenStream
impl TokenStream
sourcepub fn add_comma(&self) -> Option<(TokenStream, Span)>
pub fn add_comma(&self) -> Option<(TokenStream, Span)>
Given a TokenStream
with a Stream
of only two arguments, return a new TokenStream
separating the two arguments with a comma for diagnostic suggestions.
source§impl TokenStream
impl TokenStream
pub fn new(streams: Vec<TokenTree>) -> TokenStream
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
pub fn trees(&self) -> CursorRef<'_> ⓘ
pub fn into_trees(self) -> Cursor ⓘ
sourcepub fn eq_unspanned(&self, other: &TokenStream) -> bool
pub fn eq_unspanned(&self, other: &TokenStream) -> bool
Compares two TokenStream
s, checking equality without regarding span information.
pub fn map_enumerated<F: FnMut(usize, &TokenTree) -> TokenTree>(
self,
f: F
) -> TokenStream
sourcepub fn token_alone(kind: TokenKind, span: Span) -> TokenStream
pub fn token_alone(kind: TokenKind, span: Span) -> TokenStream
Create a token stream containing a single token with alone spacing.
sourcepub fn token_joint(kind: TokenKind, span: Span) -> TokenStream
pub fn token_joint(kind: TokenKind, span: Span) -> TokenStream
Create a token stream containing a single token with joint spacing.
sourcepub fn delimited(
span: DelimSpan,
delim: Delimiter,
tts: TokenStream
) -> TokenStream
pub fn delimited(
span: DelimSpan,
delim: Delimiter,
tts: TokenStream
) -> TokenStream
Create a token stream containing a single Delimited
.
pub fn from_ast(
node: &impl HasAttrs + HasSpan + HasTokens + Debug
) -> TokenStream
pub fn from_nonterminal_ast(nt: &Nonterminal) -> TokenStream
fn flatten_token(token: &Token, spacing: Spacing) -> TokenTree
fn flatten_token_tree(tree: &TokenTree) -> TokenTree
pub fn flattened(&self) -> TokenStream
fn try_glue_to_last(vec: &mut Vec<TokenTree>, tt: &TokenTree) -> bool
sourcepub fn push_tree(&mut self, tt: TokenTree)
pub fn push_tree(&mut self, tt: TokenTree)
Push tt
onto the end of the stream, possibly gluing it to the last
token. Uses make_mut
to maximize efficiency.
sourcepub fn push_stream(&mut self, stream: TokenStream)
pub fn push_stream(&mut self, stream: TokenStream)
Push stream
onto the end of the stream, possibly gluing the first
token tree to the last token. (No other token trees will be glued.)
Uses make_mut
to maximize efficiency.
Trait Implementations§
source§impl Clone for TokenStream
impl Clone for TokenStream
source§fn clone(&self) -> TokenStream
fn clone(&self) -> TokenStream
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for TokenStream
impl Debug for TokenStream
source§impl<__D: Decoder> Decodable<__D> for TokenStream
impl<__D: Decoder> Decodable<__D> for TokenStream
source§impl Default for TokenStream
impl Default for TokenStream
source§fn default() -> TokenStream
fn default() -> TokenStream
source§impl<__E: Encoder> Encodable<__E> for TokenStream
impl<__E: Encoder> Encodable<__E> for TokenStream
source§impl FromIterator<TokenTree> for TokenStream
impl FromIterator<TokenTree> for TokenStream
source§impl<CTX> HashStable<CTX> for TokenStreamwhere
CTX: HashStableContext,
impl<CTX> HashStable<CTX> for TokenStreamwhere
CTX: HashStableContext,
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher)
source§impl PartialEq<TokenStream> for TokenStream
impl PartialEq<TokenStream> for TokenStream
source§fn eq(&self, other: &TokenStream) -> bool
fn eq(&self, other: &TokenStream) -> bool
impl Eq for TokenStream
Auto Trait Implementations§
impl !RefUnwindSafe for TokenStream
impl !Send for TokenStream
impl !Sync for TokenStream
impl Unpin for TokenStream
impl !UnwindSafe for TokenStream
Blanket Implementations§
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: 8 bytes