Struct proc_macro::TokenStream
1.15.0 · source · [−]pub struct TokenStream(_);Expand description
The main type provided by this crate, representing an abstract stream of tokens, or, more specifically, a sequence of token trees. The type provide interfaces for iterating over those token trees and, conversely, collecting a number of token trees into one stream.
This is both the input and output of #[proc_macro], #[proc_macro_attribute]
and #[proc_macro_derive] definitions.
Implementations
impl TokenStream
source
impl TokenStream
sourcepub fn new() -> TokenStream
1.29.0 · source
pub fn new() -> TokenStream
1.29.0 · sourceReturns an empty TokenStream containing no token trees.
pub fn expand_expr(&self) -> Result<TokenStream, ExpandError>
source
pub fn expand_expr(&self) -> Result<TokenStream, ExpandError>
sourceParses this TokenStream as an expression and attempts to expand any
macros within it. Returns the expanded TokenStream.
Currently only expressions expanding to literals will succeed, although this may be relaxed in the future.
NOTE: In error conditions, expand_expr may leave macros unexpanded,
report an error, failing compilation, and/or return an Err(..). The
specific behavior for any error condition, and what conditions are
considered errors, is unspecified and may change in the future.
Trait Implementations
impl Clone for TokenStream
source
impl Clone for TokenStream
sourcefn clone(&self) -> TokenStream
source
fn clone(&self) -> TokenStream
sourceReturns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0 · source
fn clone_from(&mut self, source: &Self)
1.0.0 · sourcePerforms copy-assignment from source. Read more
impl Debug for TokenStream
source
impl Debug for TokenStream
sourcePrints token in a form convenient for debugging.
impl Default for TokenStream
1.45.0 · source
impl Default for TokenStream
1.45.0 · sourceimpl Display for TokenStream
source
impl Display for TokenStream
sourcePrints 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::Groups
with Delimiter::None delimiters and negative numeric literals.
impl Extend<TokenStream> for TokenStream
1.30.0 · source
impl Extend<TokenStream> for TokenStream
1.30.0 · sourcefn extend<I: IntoIterator<Item = TokenStream>>(&mut self, streams: I)
source
fn extend<I: IntoIterator<Item = TokenStream>>(&mut self, streams: I)
sourceExtends a collection with the contents of an iterator. Read more
fn extend_reserve(&mut self, additional: usize)
source
fn extend_reserve(&mut self, additional: usize)
sourceReserves capacity in a collection for the given number of additional elements. Read more
impl Extend<TokenTree> for TokenStream
1.30.0 · source
impl Extend<TokenTree> for TokenStream
1.30.0 · sourcefn extend<I: IntoIterator<Item = TokenTree>>(&mut self, trees: I)
source
fn extend<I: IntoIterator<Item = TokenTree>>(&mut self, trees: I)
sourceExtends a collection with the contents of an iterator. Read more
fn extend_reserve(&mut self, additional: usize)
source
fn extend_reserve(&mut self, additional: usize)
sourceReserves capacity in a collection for the given number of additional elements. Read more
impl From<TokenTree> for TokenStream
1.29.0 · source
impl From<TokenTree> for TokenStream
1.29.0 · sourceCreates a token stream containing a single token tree.
fn from(tree: TokenTree) -> TokenStream
source
fn from(tree: TokenTree) -> TokenStream
sourceConverts to this type from the input type.
impl FromIterator<TokenStream> for TokenStream
source
impl FromIterator<TokenStream> for TokenStream
sourceA “flattening” operation on token streams, collects token trees from multiple token streams into a single stream.
fn from_iter<I: IntoIterator<Item = TokenStream>>(streams: I) -> Self
source
fn from_iter<I: IntoIterator<Item = TokenStream>>(streams: I) -> Self
sourceCreates a value from an iterator. Read more
impl FromIterator<TokenTree> for TokenStream
1.29.0 · source
impl FromIterator<TokenTree> for TokenStream
1.29.0 · sourceCollects a number of token trees into a single stream.
fn from_iter<I: IntoIterator<Item = TokenTree>>(trees: I) -> Self
source
fn from_iter<I: IntoIterator<Item = TokenTree>>(trees: I) -> Self
sourceCreates a value from an iterator. Read more
impl FromStr for TokenStream
source
impl FromStr for TokenStream
sourceAttempts 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.
All tokens in the parsed stream get Span::call_site() spans.
NOTE: some errors may cause panics instead of returning LexError. We reserve the right to
change these errors into LexErrors later.
impl IntoIterator for TokenStream
1.29.0 · source
impl IntoIterator for TokenStream
1.29.0 · sourceimpl ToString for TokenStream
source
impl ToString for TokenStream
sourceimpl !Send for TokenStream
sourceimpl !Sync for TokenStream
sourceAuto Trait Implementations
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
source
impl<T> BorrowMut<T> for T where
T: ?Sized,
sourcefn borrow_mut(&mut self) -> &mut T
const: unstable · source
fn borrow_mut(&mut self) -> &mut T
const: unstable · sourceMutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
source
impl<T> ToOwned for T where
T: Clone,
sourcetype Owned = T
type Owned = T
The resulting type after obtaining ownership.
fn clone_into(&self, target: &mut T)
source
fn clone_into(&self, target: &mut T)
sourceUses borrowed data to replace owned data, usually by cloning. Read more