quip

Crates.ioquip
lib.rsquip
version0.2.0
created_at2025-11-23 17:49:40.341491+00
updated_at2025-12-11 01:35:56.524235+00
descriptionQuasi-quoting macros with expression interpolation
homepagehttps://github.com/michaelni678/quip
repositoryhttps://github.com/michaelni678/quip
max_upload_size
id1946809
size33,225
Michael (michaelni678)

documentation

https://docs.rs/quip

README

Quip

Quasi-quoting macros with expression interpolation

docs.rs     crates.io     github

Quip adds expression interpolation to several quasi-quoting macros:

Setup

Add this to your Cargo.toml:

[dependencies]
quip = "0.2.0"
quote = "1"    # For `quip!` and `quip_spanned!`.
syn = "2"      # For `parse_quip!` and `parse_quip_spanned!`.

Syntax

All Quip macros use #{...} for expression interpolation, where ... must evaluate to a type implementing quote::ToTokens. All other aspects, including repetition and hygiene, behave identically to the underlying macro.

quip! {
    impl Clone for #{item.name} {
        fn clone(&self) -> Self {
            Self {
                #(#{item.members}: self.#{item.members}.clone(),)*
            }
        }
    }
}

Behind the Scenes

Quip scans tokens and transforms each expression interpolation #{...} into a variable interpolation #... by binding the expression to a temporary variable. The macro then passes the transformed tokens to the underlying quasi-quotation macro.

quip! {
    impl MyTrait for #{item.name} {}
}

The code above expands to:

match (&item.name,) {
    (__interpolation0,) => {
        ::quote::quote! {
            impl MyTrait for #__interpolation0 {}
        }
    }
}
Commit count: 0

cargo fmt