2 unstable releases

0.1.0 Jun 5, 2024
0.0.1 May 23, 2023

#36 in #token-stream

Download history 4/week @ 2024-07-21 15/week @ 2024-07-28 3/week @ 2024-08-04 9/week @ 2024-08-11 10/week @ 2024-08-18 20/week @ 2024-08-25 9/week @ 2024-09-01 7/week @ 2024-09-08 21/week @ 2024-09-15 46/week @ 2024-09-22 31/week @ 2024-09-29 6/week @ 2024-10-06 21/week @ 2024-10-13 19/week @ 2024-10-20 19/week @ 2024-10-27 19/week @ 2024-11-03

79 downloads per month
Used in 12 crates (via quasiquote)

GPL-3.0-or-later

11KB
281 lines

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

~505KB