From 68cd090799a8552512e0713e1bad526e0b5c2999 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 20 May 2018 22:04:52 -0700 Subject: [PATCH] Eliminate references to Tokens --- README.md | 11 +++++------ src/lib.rs | 4 ++-- src/to_tokens.rs | 11 +++++++++-- tests/test.rs | 4 ++-- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 1297405..503999a 100644 --- a/README.md +++ b/README.md @@ -44,13 +44,12 @@ extern crate quote; ## Syntax The quote crate provides a [`quote!`] macro within which you can write Rust code -that gets packaged into a [`quote::Tokens`] and can be treated as data. You -should think of `Tokens` as representing a fragment of Rust source code. Call -`to_string()` on a `Tokens` to get back the fragment of source code as a string, -or call `into()` to stream them as a `TokenStream` back to the compiler in a -procedural macro. +that gets packaged into a [`TokenStream`] and can be treated as data. You should +think of `TokenStream` as representing a fragment of Rust source code. This type +can be returned directly back to the compiler by a procedural macro to get +compiled into the caller's crate. -[`quote::Tokens`]: https://docs.rs/quote/0.6/quote/struct.Tokens.html +[`TokenStream`]: https://docs.rs/proc-macro2/0.4/proc_macro2/struct.TokenStream.html Within the `quote!` macro, interpolation is done with `#var`. Any type implementing the [`quote::ToTokens`] trait can be interpolated. This includes diff --git a/src/lib.rs b/src/lib.rs index 84f8d97..e770a73 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -123,10 +123,10 @@ pub mod __rt { /// The whole point. /// /// Performs variable interpolation against the input and produces it as -/// [`Tokens`]. For returning tokens to the compiler in a procedural macro, use +/// [`TokenStream`]. For returning tokens to the compiler in a procedural macro, use /// `into()` to build a `TokenStream`. /// -/// [`Tokens`]: struct.Tokens.html +/// [`TokenStream`]: https://docs.rs/proc-macro2/0.4/proc_macro2/struct.TokenStream.html /// /// # Interpolation /// diff --git a/src/to_tokens.rs b/src/to_tokens.rs index 31db28f..243431d 100644 --- a/src/to_tokens.rs +++ b/src/to_tokens.rs @@ -8,7 +8,14 @@ use proc_macro2::{Group, Ident, Literal, Punct, Span, TokenStream, TokenTree}; /// /// [`quote!`]: macro.quote.html pub trait ToTokens { - /// Write `self` to the given `Tokens`. + /// Write `self` to the given `TokenStream`. + /// + /// The token append methods provided by the [`TokenStreamExt`] extension + /// trait may be useful for implementing `ToTokens`. + /// + /// [`TokenStreamExt`]: trait.TokenStreamExt.html + /// + /// # Example /// /// Example implementation for a struct representing Rust paths like /// `std::cmp::PartialEq`: @@ -50,7 +57,7 @@ pub trait ToTokens { /// ``` fn to_tokens(&self, tokens: &mut TokenStream); - /// Convert `self` directly into a `Tokens` object. + /// 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. diff --git a/tests/test.rs b/tests/test.rs index e7ef8e6..6f0ac89 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -21,7 +21,7 @@ impl quote::ToTokens for X { fn test_quote_impl() { let tokens = quote! { impl<'a, T: ToTokens> ToTokens for &'a T { - fn to_tokens(&self, tokens: &mut Tokens) { + fn to_tokens(&self, tokens: &mut TokenStream) { (**self).to_tokens(tokens) } } @@ -29,7 +29,7 @@ fn test_quote_impl() { let expected = concat!( "impl < 'a , T : ToTokens > ToTokens for & 'a T { ", - "fn to_tokens ( & self , tokens : & mut Tokens ) { ", + "fn to_tokens ( & self , tokens : & mut TokenStream ) { ", "( * * self ) . to_tokens ( tokens ) ", "} ", "}"