Trait ToTokens

Source
pub trait ToTokens {
    // Required method
    fn to_tokens(&self, tokens: &mut TokenStream);

    // Provided methods
    fn to_token_stream(&self) -> TokenStream { ... }
    fn into_token_stream(self) -> TokenStream
       where Self: Sized { ... }
}
Expand description

Types that can be interpolated inside a quote! invocation.

Required Methods§

Source

fn to_tokens(&self, tokens: &mut TokenStream)

Write self to the given TokenStream.

The token append methods provided by the TokenStreamExt extension trait may be useful for implementing ToTokens.

§Example

Example implementation for a struct representing Rust paths like std::cmp::PartialEq:

use proc_macro2::{TokenTree, Spacing, Span, Punct, TokenStream};
use quote::{TokenStreamExt, ToTokens};

pub struct Path {
    pub global: bool,
    pub segments: Vec<PathSegment>,
}

impl ToTokens for Path {
    fn to_tokens(&self, tokens: &mut TokenStream) {
        for (i, segment) in self.segments.iter().enumerate() {
            if i > 0 || self.global {
                // Double colon `::`
                tokens.append(Punct::new(':', Spacing::Joint));
                tokens.append(Punct::new(':', Spacing::Alone));
            }
            segment.to_tokens(tokens);
        }
    }
}

Provided Methods§

Source

fn to_token_stream(&self) -> TokenStream

Convert self directly into a TokenStream object.

This method is implicitly implemented using to_tokens, and acts as a convenience method for consumers of the ToTokens trait.

Source

fn into_token_stream(self) -> TokenStream
where Self: Sized,

Convert self directly into a TokenStream object.

This method is implicitly implemented using to_tokens, and acts as a convenience method for consumers of the ToTokens trait.

Implementations on Foreign Types§

Source§

impl ToTokens for TokenTree

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Lit

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for bool

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for char

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for f32

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for f64

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for i8

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for i16

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for i32

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for i64

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for i128

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for isize

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for str

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for u8

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for u16

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for u32

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for u64

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for u128

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for usize

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for CString

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for String

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for CStr

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Group

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Ident

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Literal

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Punct

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for TokenStream

Source§

impl ToTokens for Lifetime

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for LitBool

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for LitByte

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for LitByteStr

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for LitCStr

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for LitChar

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for LitFloat

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for LitInt

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for LitStr

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Nothing

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Abstract

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for And

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for AndAnd

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for AndEq

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for As

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Async

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for At

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Auto

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Await

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Become

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Box

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Break

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Caret

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for CaretEq

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Colon

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Comma

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Const

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Continue

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Crate

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Default

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Do

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Dollar

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Dot

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for DotDot

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for DotDotDot

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for DotDotEq

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Dyn

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Else

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Enum

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Eq

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for EqEq

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Extern

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for FatArrow

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Final

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Fn

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for For

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Ge

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Gt

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for If

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Impl

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for In

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for LArrow

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Le

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Let

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Loop

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Lt

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Macro

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Match

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Minus

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for MinusEq

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Mod

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Move

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Mut

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Ne

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Not

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Or

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for OrEq

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for OrOr

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Override

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for PathSep

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Percent

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for PercentEq

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Plus

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for PlusEq

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Pound

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Priv

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Pub

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Question

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for RArrow

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Raw

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Ref

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Return

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for SelfType

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for SelfValue

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Semi

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Shl

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for ShlEq

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Shr

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for ShrEq

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Slash

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for SlashEq

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Star

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for StarEq

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Static

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Struct

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Super

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Tilde

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Trait

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Try

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Type

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Typeof

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Underscore

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Union

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Unsafe

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Unsized

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Use

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Virtual

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Where

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for While

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl ToTokens for Yield

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl<'a, T> ToTokens for Cow<'a, T>
where T: ToOwned + ToTokens + ?Sized,

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl<T> ToTokens for Option<T>
where T: ToTokens,

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl<T> ToTokens for &T
where T: ToTokens + ?Sized,

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl<T> ToTokens for &mut T
where T: ToTokens + ?Sized,

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl<T> ToTokens for Box<T>
where T: ToTokens + ?Sized,

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl<T> ToTokens for Rc<T>
where T: ToTokens + ?Sized,

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl<T, P> ToTokens for Pair<T, P>
where T: ToTokens, P: ToTokens,

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Source§

impl<T, P> ToTokens for Punctuated<T, P>
where T: ToTokens, P: ToTokens,

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Implementors§