#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

#149 in Procedural macros

Download history 9/week @ 2024-09-11 28/week @ 2024-09-18 26/week @ 2024-09-25 21/week @ 2024-10-02 16/week @ 2024-10-09 16/week @ 2024-10-16 17/week @ 2024-10-23 18/week @ 2024-10-30 18/week @ 2024-11-06 5/week @ 2024-11-13 18/week @ 2024-11-20 66/week @ 2024-11-27 63/week @ 2024-12-04 84/week @ 2024-12-11 44/week @ 2024-12-18 1/week @ 2024-12-25

204 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

~530KB