#quote #macro #proc-macro #expressions #interpolation #syntax #compatible

quasiquote

quote compatible quasiquote macro with support for interpolating expressions

3 unstable releases

0.1.1 Jun 5, 2024
0.1.0 Jun 5, 2024
0.0.1 May 23, 2023
0.0.0 May 2, 2023

#152 in Procedural macros

Download history 25/week @ 2024-09-28 9/week @ 2024-10-05 21/week @ 2024-10-12 17/week @ 2024-10-19 15/week @ 2024-10-26 22/week @ 2024-11-02 8/week @ 2024-11-09 12/week @ 2024-11-16 31/week @ 2024-11-23 62/week @ 2024-11-30 87/week @ 2024-12-07 74/week @ 2024-12-14 14/week @ 2024-12-21 8/week @ 2024-12-28 40/week @ 2025-01-04 46/week @ 2025-01-11

120 downloads per month
Used in 16 crates (8 directly)

GPL-3.0-or-later

18KB

Provides a wrapper around quote! that allows interpolating arbitrary expressions.

Expected syntax is identical to what's used for quote!, except that a new interpolation pattern is allowed.

Examples

With quote:

use quote::quote;
use proc_macro2::TokenStream;
use syn::{Field, Member};

pub fn expand_getter(field: &Field) -> TokenStream {
    let ident = &field.ident;
    let member = Member::Named(ident.as_ref().cloned().unwrap());
    let ty = &field.ty;
    quote! {
        pub fn #ident(&self) -> #ty {
            &self.#member
        }
    }
}

With quasiquote:

use quasiquote::quasiquote;
use proc_macro2::TokenStream;
use syn::{Field, Member};

pub fn expand_getter(field: &Field) -> TokenStream {
    let member = Member::Named(field.ident.as_ref().cloned().unwrap());
    quasiquote! {
        pub fn #{&field.ident}(&self) -> #{&field.ty} {
            &self.#member
        }
    }
}

Not yet implemented

  • interpolation of expressions inside of repetitions

Dependencies

~525KB