pub struct TokenStream { /* private fields */ }
Expand description
An abstract stream of tokens, or more concretely a sequence of token trees.
This type provides interfaces for iterating over token trees and for collecting token trees into one stream.
Token stream is both the input and output of #[proc_macro]
,
#[proc_macro_attribute]
and #[proc_macro_derive]
definitions.
Implementations§
Source§impl TokenStream
impl TokenStream
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
Prints token in a form convenient for debugging.
impl Debug for TokenStream
Prints token in a form convenient for debugging.
Source§impl Default for TokenStream
TokenStream::default()
returns an empty stream,
i.e. this is equivalent with TokenStream::new()
.
impl Default for TokenStream
TokenStream::default()
returns an empty stream,
i.e. this is equivalent with TokenStream::new()
.
Source§fn default() -> TokenStream
fn default() -> TokenStream
Source§impl Display for TokenStream
Prints the token stream as a string that is supposed to be losslessly
convertible back into the same token stream (modulo spans), except for
possibly TokenTree::Group
s with Delimiter::None
delimiters and negative
numeric literals.
impl Display for TokenStream
Prints the token stream as a string that is supposed to be losslessly
convertible back into the same token stream (modulo spans), except for
possibly TokenTree::Group
s with Delimiter::None
delimiters and negative
numeric literals.
Source§impl Extend<TokenStream> for TokenStream
impl Extend<TokenStream> for TokenStream
Source§fn extend<I>(&mut self, streams: I)where
I: IntoIterator<Item = TokenStream>,
fn extend<I>(&mut self, streams: I)where
I: IntoIterator<Item = TokenStream>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl Extend<TokenTree> for TokenStream
impl Extend<TokenTree> for TokenStream
Source§fn extend<I>(&mut self, streams: I)where
I: IntoIterator<Item = TokenTree>,
fn extend<I>(&mut self, streams: I)where
I: IntoIterator<Item = TokenTree>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl From<TokenStream> for TokenStream
impl From<TokenStream> for TokenStream
Source§fn from(inner: TokenStream) -> TokenStream
fn from(inner: TokenStream) -> TokenStream
Source§impl From<TokenTree> for TokenStream
impl From<TokenTree> for TokenStream
Source§fn from(token: TokenTree) -> TokenStream
fn from(token: TokenTree) -> TokenStream
Source§impl FromIterator<TokenStream> for TokenStream
impl FromIterator<TokenStream> for TokenStream
Source§fn from_iter<I>(streams: I) -> TokenStreamwhere
I: IntoIterator<Item = TokenStream>,
fn from_iter<I>(streams: I) -> TokenStreamwhere
I: IntoIterator<Item = TokenStream>,
Source§impl FromIterator<TokenTree> for TokenStream
Collects a number of token trees into a single stream.
impl FromIterator<TokenTree> for TokenStream
Collects a number of token trees into a single stream.
Source§fn from_iter<I>(streams: I) -> TokenStreamwhere
I: IntoIterator<Item = TokenTree>,
fn from_iter<I>(streams: I) -> TokenStreamwhere
I: IntoIterator<Item = TokenTree>,
Source§impl FromStr for TokenStream
Attempts to break the string into tokens and parse those tokens into a token
stream.
impl FromStr for TokenStream
Attempts to break the string into tokens and parse those tokens into a token stream.
May fail for a number of reasons, for example, if the string contains unbalanced delimiters or characters not existing in the language.
NOTE: Some errors may cause panics instead of returning LexError
. We
reserve the right to change these errors into LexError
s later.
Source§impl IntoIterator for TokenStream
impl IntoIterator for TokenStream
Source§impl Parser for TokenStream
Parses a TokenStream
from the input tokens. This is the primary entity to parse when
dealing with opaque entities where internal details are left out.
Note that this matches a empty stream (see EndOfStream
) as well.
impl Parser for TokenStream
Parses a TokenStream
from the input tokens. This is the primary entity to parse when
dealing with opaque entities where internal details are left out.
Note that this matches a empty stream (see EndOfStream
) as well.
Source§fn parser(
tokens: &mut ShadowCountedIter<'_, <TokenStream as IntoIterator>::IntoIter>,
) -> Result<TokenStream, Error>
fn parser( tokens: &mut ShadowCountedIter<'_, <TokenStream as IntoIterator>::IntoIter>, ) -> Result<TokenStream, Error>
tokens
iterator directly. It should not be called from user code except for implementing
parsers itself and then only when the rules below are followed. Read moreSource§impl ToTokens for TokenStream
impl ToTokens for TokenStream
Source§fn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
&self
to the given TokenStream
.Source§fn to_token_iter(
&self,
) -> ShadowCountedIter<'_, <TokenStream as IntoIterator>::IntoIter> ⓘ
fn to_token_iter( &self, ) -> ShadowCountedIter<'_, <TokenStream as IntoIterator>::IntoIter> ⓘ
&self
into a TokenIter
object.Source§fn into_token_iter<'a>(
self,
) -> ShadowCountedIter<'a, <TokenStream as IntoIterator>::IntoIter> ⓘwhere
Self: Sized,
fn into_token_iter<'a>(
self,
) -> ShadowCountedIter<'a, <TokenStream as IntoIterator>::IntoIter> ⓘwhere
Self: Sized,
self
into a TokenIter
object.Source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
&self
into a TokenStream
object.Source§fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
self
into a TokenStream
object.Source§impl TryFrom<TokenStream> for NonEmptyTokenStream
impl TryFrom<TokenStream> for NonEmptyTokenStream
Auto Trait Implementations§
impl Freeze for TokenStream
impl RefUnwindSafe for TokenStream
impl !Send for TokenStream
impl !Sync for TokenStream
impl Unpin for TokenStream
impl UnwindSafe for TokenStream
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Parse for Twhere
T: Parser,
impl<T> Parse for Twhere
T: Parser,
Source§fn parse(
tokens: &mut ShadowCountedIter<'_, <TokenStream as IntoIterator>::IntoIter>,
) -> Result<Self, Error>
fn parse( tokens: &mut ShadowCountedIter<'_, <TokenStream as IntoIterator>::IntoIter>, ) -> Result<Self, Error>
parser()
within a
transaction. Commits changes on success and returns the parsed value. Read moreSource§fn parse_all(
tokens: &mut ShadowCountedIter<'_, <TokenStream as IntoIterator>::IntoIter>,
) -> Result<Self, Error>
fn parse_all( tokens: &mut ShadowCountedIter<'_, <TokenStream as IntoIterator>::IntoIter>, ) -> Result<Self, Error>
EndOfStream
at the end. Thus it will error if parsing is not exhaustive. Read moreSource§fn parse_with<T>(
tokens: &mut ShadowCountedIter<'_, <TokenStream as IntoIterator>::IntoIter>,
f: impl FnOnce(Self, &mut ShadowCountedIter<'_, <TokenStream as IntoIterator>::IntoIter>) -> Result<T, Error>,
) -> Result<T, Error>
fn parse_with<T>( tokens: &mut ShadowCountedIter<'_, <TokenStream as IntoIterator>::IntoIter>, f: impl FnOnce(Self, &mut ShadowCountedIter<'_, <TokenStream as IntoIterator>::IntoIter>) -> Result<T, Error>, ) -> Result<T, Error>
FnOnce(Self, &mut TokenIter) -> Result<T>
closure which
creates a new result or returns an Error. Read more