qemit
qemit is a minimalist quasi-quoting library for Rust. It provides a lightweight, declarative macro-based alternative to the quote crate, designed specifically for procedural macros or code generation tasks where a small dependency footprint is preferred.
qemit!
Features
- Small Footprint: Minimal dependencies (only
proc_macro2). - Standard Syntax: Uses the familiar
~variablesyntax for interpolation. - Recursive Groups: Automatically handles nested braces
{}, parentheses(), and brackets[]. - Declarative: Built entirely with
macro_rules!, avoiding the need for a procedural macro to power the quoting itself.
Installation
Add qemit to your Cargo.toml:
[]
= "0.1.0"
Usage
The primary entry point is the qemit! macro. It returns a proc_macro2::TokenStream.
Basic Quoting
use qemit;
let tokens = qemit! ;
Interpolation
Use the ~ operator to inject variables that implement the ToTokens trait.
use qemit;
use ;
let fn_name = new;
let body = qemit! ;
let tokens = qemit! ;
Nested Interpolation
qemit correctly recurses into groups, allowing you to interpolate values deep within blocks or expressions:
let value = i32_unsuffixed;
let tokens = qemit! ;
How it Works
Unlike traditional quasi-quoting libraries that use procedural macros to parse their own input, qemit uses a sliding window technique in declarative macros. It processes tokens by looking at a context of surrounding tokens to identify the ~ operator and its target.
This makes it extremely fast to compile and suitable for projects where adding a heavy build-dependency tree is undesirable.
Trait: ToTokens
To make a custom type compatible with qemit!, implement the ToTokens trait:
License
This project is dually licensed under:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Cheers, RazkarStudio.
© 2026 RazkarStudio. All rights reserved.