virtue::prelude

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 { ... }
}
🔬This is a nightly-only experimental API. (proc_macro_totokens)
Expand description

Types that can be interpolated inside a quote! invocation.

Required Methods§

Source

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)

Write self to the given TokenStream.

§Example

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

#![feature(proc_macro_totokens)]

use std::iter;
use proc_macro::{Spacing, Punct, TokenStream, TokenTree, 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.extend(iter::once(TokenTree::from(Punct::new(':', Spacing::Joint))));
                tokens.extend(iter::once(TokenTree::from(Punct::new(':', Spacing::Alone))));
            }
            segment.to_tokens(tokens);
        }
    }
}

Provided Methods§

Source

fn to_token_stream(&self) -> TokenStream

🔬This is a nightly-only experimental API. (proc_macro_totokens)

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,

🔬This is a nightly-only experimental API. (proc_macro_totokens)

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 bool

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

impl ToTokens for char

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

impl ToTokens for f32

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

impl ToTokens for f64

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

impl ToTokens for i8

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

impl ToTokens for i16

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

impl ToTokens for i32

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

impl ToTokens for i64

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

impl ToTokens for i128

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

impl ToTokens for isize

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

impl ToTokens for str

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

impl ToTokens for u8

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

impl ToTokens for u16

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

impl ToTokens for u32

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

impl ToTokens for u64

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

impl ToTokens for u128

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

impl ToTokens for usize

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

impl ToTokens for CString

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

impl ToTokens for String

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

impl ToTokens for CStr

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

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

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

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

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

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

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

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

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

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

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)
Source§

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

Source§

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

🔬This is a nightly-only experimental API. (proc_macro_totokens)

Implementors§