#quote #string #token-stream #popular #backed #sorting #macro

squote

A clone of the quote crate that uses a String as its backing store

3 releases

0.1.2 Aug 3, 2020
0.1.1 Jul 31, 2020
0.1.0 Jul 31, 2020

#1038 in Rust patterns

Download history 236/week @ 2023-12-04 252/week @ 2023-12-11 315/week @ 2023-12-18 229/week @ 2023-12-25 122/week @ 2024-01-01 207/week @ 2024-01-08 164/week @ 2024-01-15 149/week @ 2024-01-22 104/week @ 2024-01-29 162/week @ 2024-02-05 224/week @ 2024-02-12 207/week @ 2024-02-19 184/week @ 2024-02-26 265/week @ 2024-03-04 187/week @ 2024-03-11 231/week @ 2024-03-18

873 downloads per month

MIT license

33KB
788 lines

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()
}

No runtime deps