Skip to main content

Crate qemit

Crate qemit 

Source
Expand description

§qemit

qemit is a minimal quasi-quoting library designed as a lightweight alternative to quote. It allows for the construction of proc_macro2::TokenStream objects using a declarative syntax, including support for variable interpolation using the ~ operator.

§Core Concepts

The library revolves around the qemit! macro, which consumes standard Rust tokens and converts them into a TokenStream.

§Interpolation

You can inject external variables into the stream using the tilde (~) operator. Any type implementing the ToTokens trait can be interpolated.

use qemit::qemit;
let name = "World";
let tokens = qemit! { println!("Hello, ~name"); };

§Nested Groups

The macro recursively handles groups—tokens enclosed in (), {}, or []. This ensures that interpolation works correctly even deep inside function bodies or complex expressions.

§Technical Implementation

qemit uses a “sliding window” declarative macro technique. It processes tokens by looking at the current token tree (tt) and its immediate neighbors to identify the ~ $var pattern without requiring a procedural macro for the transformation logic.

Re-exports§

pub use proc_macro2;

Macros§

qemit
The primary entry point for quasi-quoting.

Traits§

ToTokens
A trait for types that can be converted into a sequence of token trees.