#proc-macro #quote

macro quote2-macros

An alternative lightweight version of quote

7 releases (breaking)

0.9.0 Oct 8, 2024
0.8.0 Oct 2, 2024
0.7.0 Jul 4, 2023
0.5.0 Jul 3, 2023
0.1.0 Jul 1, 2023

#128 in #quote

Download history 145/week @ 2025-10-26 404/week @ 2025-11-02 343/week @ 2025-11-09 272/week @ 2025-11-16 285/week @ 2025-11-23 428/week @ 2025-11-30 246/week @ 2025-12-07 197/week @ 2025-12-14 281/week @ 2025-12-21 303/week @ 2025-12-28 294/week @ 2026-01-04 322/week @ 2026-01-11 511/week @ 2026-01-18 566/week @ 2026-01-25 440/week @ 2026-02-01 260/week @ 2026-02-08

1,787 downloads per month
Used in 16 crates (via quote2)

MIT license

9KB
183 lines

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

No runtime deps