quote2

Crates.ioquote2
lib.rsquote2
version0.9.0
created_at2023-07-01 17:50:40.223349+00
updated_at2024-10-08 17:36:51.864838+00
descriptionAn alternative lightweight version of quote
homepage
repositoryhttps://github.com/nurmohammed840/quote2
max_upload_size
id905613
size7,922
Nur (nurmohammed840)

documentation

README

quote2

An alternative lightweight version of quote.

Crates.io Documentation License: MIT

Features

  • Very lightweight and produces extremely lean, minimal code compare to quote

  • Unlike quote, quote2 allows direct mutation of tokens without creating new TokenStream instances, enhancing runtime performance.

    similar to write macro.

Example

Add it as a dependency to your Rust project by adding the following line to your Cargo.toml file:

[dependencies]
quote2 = "0.9"
use quote2::{proc_macro2::TokenStream, quote, Quote};

let body = quote(|t| {
    for n in 1..7 {
        if n % 2 == 0 {
            quote!(t, {
                println!("{}", #n);
            });
        }
    }
});

let mut t = TokenStream::new();
quote!(t, {
    fn main() {
        #body
    }
});

Generated code:

fn main() {
    println!("{}", 2i32);
    println!("{}", 4i32);
    println!("{}", 6i32);
}
Commit count: 22

cargo fmt