quasiquote

Crates.ioquasiquote
lib.rsquasiquote
version0.1.1
sourcesrc
created_at2023-05-02 19:05:35.050588
updated_at2024-06-05 21:09:58.337837
descriptionquote compatible quasiquote macro with support for interpolating expressions
homepagehttps://github.com/fearless-cow/quasiquote
repositoryhttps://github.com/fearless-cow/quasiquote
max_upload_size
id854829
size52,178
(fearless-cow)

documentation

README

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
Commit count: 34

cargo fmt