Trait quote_use::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 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<'a, T> ToTokens for &'a T
where T: ToTokens + ?Sized,

source§

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

source§

impl<'a, T> ToTokens for &'a mut T
where T: 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 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§