5 releases (3 breaking)

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

#97 in Procedural macros

Download history 174/week @ 2024-10-24 170/week @ 2024-10-31 50/week @ 2024-11-07 82/week @ 2024-11-14 113/week @ 2024-11-21 121/week @ 2024-11-28 181/week @ 2024-12-05 156/week @ 2024-12-12 170/week @ 2024-12-19 305/week @ 2024-12-26 449/week @ 2025-01-02 245/week @ 2025-01-09 292/week @ 2025-01-16 494/week @ 2025-01-23 423/week @ 2025-01-30 548/week @ 2025-02-06

1,841 downloads per month
Used in 7 crates (2 directly)

MIT license

8KB
158 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);
}

Dependencies

~105KB