<div align="center">
# qemit
[](https://doc.rust-lang.org/edition-guide/rust-2024/)
[](https://crates.io/crates/qemit)
[](https://docs.rs/qemit)
[](https://codeberg.org/razkar/qemit/src/branch/main/LICENSE-MIT)
[](https://codeberg.org/razkar/qemit/src/branch/main/LICENSE-APACHE)
[](https://crates.io/crates/qemit)
[](https://deps.rs/repo/codeberg/razkar/qemit)
[](https://codeberg.org/razkar/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.
</div>
```rust
qemit! {
fn hello() { ~world }
}
```
## Features
- **Small Footprint**: Minimal dependencies (only `proc_macro2`).
- **Standard Syntax**: Uses the familiar `~variable` syntax 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`:
```toml
[dependencies]
qemit = "0.1.0"
````
## Usage
The primary entry point is the `qemit!` macro. It returns a `proc_macro2::TokenStream`.
### Basic Quoting
```rust
use qemit::qemit;
let tokens = qemit! {
fn hello_world() {
println!("Hello from qemit!");
}
};
```
### Interpolation
Use the `~` operator to inject variables that implement the `ToTokens` trait.
```rust
use qemit::qemit;
use proc_macro2::{Ident, Span};
let fn_name = Ident::new("dynamic_function", Span::call_site());
let body = qemit! { println!("Inside the function"); };
let tokens = qemit! {
fn ~fn_name() {
~body
}
};
```
### Nested Interpolation
`qemit` correctly recurses into groups, allowing you to interpolate values deep within blocks or expressions:
```rust
let value = proc_macro2::Literal::i32_unsuffixed(42);
let tokens = qemit! {
{
{
let x = ~value;
}
}
};
```
## 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:
```rust
impl qemit::ToTokens for MyType {
fn to_tokens(&self, tokens: &mut qemit::proc_macro2::TokenStream) {
// Append your tokens here
}
}
```
## License
This project is dually licensed under:
- **Apache License, Version 2.0** ([LICENSE-APACHE](https://www.google.com/search?q=LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
- **MIT License** ([LICENSE-MIT](https://www.google.com/search?q=LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.
Cheers, RazkarStudio.
© 2026 RazkarStudio. All rights reserved.