# 1.15.0[−][src]Struct proc_macro::TokenStream

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

## Methods

### `impl TokenStream`[src]

#### `pub fn new() -> TokenStream` 1.29.0[src]

Returns an empty `TokenStream` containing no token trees.

#### `pub fn is_empty(&self) -> bool` 1.29.0[src]

Checks if this `TokenStream` is empty.

## Trait Implementations

### `impl !Send for TokenStream`[src]

### `impl From<TokenTree> for TokenStream` 1.29.0[src]

Creates a token stream containing a single token tree.

#### `fn from(tree: TokenTree) -> TokenStream`[src]

Performs the conversion.

### `impl !Sync for TokenStream`[src]

### `impl Extend<TokenTree> for TokenStream` 1.30.0[src]

#### `fn extend<I: IntoIterator<Item = TokenTree>>(&mut self, trees: I)`[src]

Extends a collection with the contents of an iterator. Read more

### `impl Extend<TokenStream> for TokenStream` 1.30.0[src]

#### `fn extend<I: IntoIterator<Item = TokenStream>>(&mut self, streams: I)`[src]

Extends a collection with the contents of an iterator. Read more

### `impl Clone for TokenStream`[src]

#### `fn clone(&self) -> TokenStream`[src]

Returns a copy of the value. Read more

#### `fn clone_from(&mut self, source: &Self)`1.0.0[src]

Performs copy-assignment from `source`. Read more

### `impl IntoIterator for TokenStream` 1.29.0[src]

#### `type Item = TokenTree`

The type of the elements being iterated over.

#### `type IntoIter = IntoIter`

Which kind of iterator are we turning this into?

####
ⓘImportant traits for IntoIter

### Important traits for IntoIter

`impl Iterator for IntoIter type Item = TokenTree;`
`fn into_iter(self) -> IntoIter`[src]

Creates an iterator from a value. Read more

### `impl ToString for TokenStream`[src]

#### `fn to_string(&self) -> String`[src]

Converts the given value to a `String`. Read more

### `impl Debug for TokenStream`[src]

Prints token in a form convenient for debugging.

#### `fn fmt(&self, f: &mut Formatter) -> Result`[src]

Formats the value using the given formatter. Read more

### `impl Display for TokenStream`[src]

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.

#### `fn fmt(&self, f: &mut Formatter) -> Result`[src]

Formats the value using the given formatter. Read more

### `impl FromStr for TokenStream`[src]

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. 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 `LexError`s later.

#### `type Err = LexError`

The associated error which can be returned from parsing.

#### `fn from_str(src: &str) -> Result<TokenStream, LexError>`[src]

Parses a string `s` to return a value of this type. Read more

### `impl FromIterator<TokenTree> for TokenStream` 1.29.0[src]

Collects a number of token trees into a single stream.

#### `fn from_iter<I: IntoIterator<Item = TokenTree>>(trees: I) -> Self`[src]

Creates a value from an iterator. Read more

### `impl FromIterator<TokenStream> for TokenStream`[src]

A "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`[src]

Creates a value from an iterator. Read more

## Blanket Implementations

### `impl<T> From<T> for T`[src]

#### `fn from(t: T) -> T`[src]

Performs the conversion.

### `impl<T> ToOwned for T where
T: Clone,` [src]

#### `type Owned = T`

The resulting type after obtaining ownership.

#### `fn to_owned(&self) -> T`[src]

Creates owned data from borrowed data, usually by cloning. Read more

#### `fn clone_into(&self, target: &mut T)`[src]

🔬 This is a nightly-only experimental API. (`toowned_clone_into` #41263)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

### `impl<I> IntoIterator for I where
I: Iterator,` [src]

#### `type Item = <I as Iterator>::Item`

The type of the elements being iterated over.

#### `type IntoIter = I`

Which kind of iterator are we turning this into?

#### `fn into_iter(self) -> I`[src]

Creates an iterator from a value. Read more

### `impl<T> ToString for T where
T: Display + ?Sized,` [src]

#### `default fn to_string(&self) -> String`[src]

Converts the given value to a `String`. Read more

### `impl<T, U> Into<U> for T where
U: From<T>,` [src]

#### `fn into(self) -> U`[src]

Performs the conversion.

### `impl<T, U> TryFrom<U> for T where
U: Into<T>,` [src]

#### `type Error = Infallible`

The type returned in the event of a conversion error.

#### `fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>`[src]

Performs the conversion.

### `impl<T, U> TryInto<U> for T where
U: TryFrom<T>,` [src]

#### `type Error = <U as TryFrom<T>>::Error`

The type returned in the event of a conversion error.

#### `fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>`[src]

Performs the conversion.

### `impl<T> BorrowMut<T> for T where
T: ?Sized,` [src]

#### `fn borrow_mut(&mut self) -> &mut T`[src]

Mutably borrows from an owned value. Read more

### `impl<T> Borrow<T> for T where
T: ?Sized,` [src]

#### `fn borrow(&self) -> &T`[src]

Immutably borrows from an owned value. Read more

### `impl<T> Any for T where
T: 'static + ?Sized,` [src]

#### `fn type_id(&self) -> TypeId`[src]

Gets the `TypeId` of `self`. Read more

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)