squote

Crates.iosquote
lib.rssquote
version0.1.2
sourcesrc
created_at2020-07-31 12:53:09.425989
updated_at2020-08-03 10:15:34.160426
descriptionA clone of the quote crate that uses a String as its backing store
homepage
repositoryhttps://github.com/rylev/squote
max_upload_size
id271629
size48,807
Ryan Levick (rylev)

documentation

https://docs.rs/squote

README

crates.io docs.rs Build and Test

squote

A string backed implementation of the popular quote crate.

This crate vs. quote

When in doubt always prefer using quote. This crate was created because for very large code generation, quote can be slow when compared to simple string concatenation. If you're code generation never uses incoming TokenStreams (i.e., from a macro of some sort), then you might see some performance gain using this crate.

There is active work to see if the performance gains from this crate can be merged into the quote crate in which case this crate would be deprecated.

Usage

use proc_macro::TokenStream;
use squote::quote;

#[proc_macro]
pub fn my_macro(stream: TokenStream) -> TokenStream {
    let tokens = quote! {
        impl<'a, T: ToTokens> ToTokens for &'a T {
            fn to_tokens(&self, tokens: &mut TokenStream) {
                (**self).to_tokens(tokens)
            }
        }
    };
    s.parse::<TokenStream>().unwrap()
}
Commit count: 10

cargo fmt