Struct TokenStream

struct TokenStream(_)

The main type provided by this crate, representing an abstract stream of tokens, or, more specifically, a sequence of token trees. The type provides 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

fn new() -> TokenStream

Returns an empty TokenStream containing no token trees.

fn is_empty(self: &Self) -> bool

Checks if this TokenStream is empty.

fn expand_expr(self: &Self) -> Result<TokenStream, ExpandError>

Parses 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.

impl Clone for TokenStream

fn clone(self: &Self) -> TokenStream

impl Debug for TokenStream

fn fmt(self: &Self, f: &mut fmt::Formatter<'_>) -> fmt::Result

impl Default for TokenStream

fn default() -> Self

impl Display for TokenStream

fn fmt(self: &Self, f: &mut fmt::Formatter<'_>) -> fmt::Result

impl Extend for TokenStream

fn extend<T: IntoIterator<Item = Literal>>(self: &mut Self, iter: T)

impl Extend for TokenStream

fn extend<I: IntoIterator<Item = TokenTree>>(self: &mut Self, trees: I)

impl Extend for TokenStream

fn extend<T: IntoIterator<Item = Group>>(self: &mut Self, iter: T)

impl Extend for TokenStream

fn extend<T: IntoIterator<Item = Ident>>(self: &mut Self, iter: T)

impl Extend for TokenStream

fn extend<I: IntoIterator<Item = TokenStream>>(self: &mut Self, streams: I)

impl Extend for TokenStream

fn extend<T: IntoIterator<Item = Punct>>(self: &mut Self, iter: T)

impl Freeze for TokenStream

impl From for TokenStream

fn from(tree: TokenTree) -> TokenStream

impl FromIterator for TokenStream

fn from_iter<I: IntoIterator<Item = TokenTree>>(trees: I) -> Self

impl FromIterator for TokenStream

fn from_iter<I: IntoIterator<Item = TokenStream>>(streams: I) -> Self

impl FromStr for TokenStream

fn from_str(src: &str) -> Result<TokenStream, LexError>

impl IntoIterator for crate::TokenStream

fn into_iter(self: Self) -> IntoIter

impl RefUnwindSafe for TokenStream

impl Send for TokenStream

impl Sync for TokenStream

impl ToTokens for crate::TokenStream

fn to_tokens(self: &Self, tokens: &mut TokenStream)
fn into_token_stream(self: Self) -> TokenStream

impl Unpin for TokenStream

impl UnwindSafe for TokenStream

impl<T> Any for TokenStream

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for TokenStream

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for TokenStream

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for TokenStream

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for TokenStream

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for TokenStream

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> ToString for TokenStream

fn to_string(self: &Self) -> String

impl<T, U> Into for TokenStream

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for TokenStream

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for TokenStream

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>