qemit 0.1.0

A minimalist quasi-quoting library using declarative macros
Documentation
  • Coverage
  • 100%
    4 out of 4 items documented2 out of 4 items with examples
  • Size
  • Source code size: 26.91 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.26 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 41s Average build duration of successful builds.
  • all releases: 41s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • razkar-studio

qemit

Rust Version Crates.io Version docs.rs License MIT License Apache-2.0 Crates.io Downloads Deps.rs Maintenance

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! {
    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:

[dependencies]
qemit = "0.1.0"

Usage

The primary entry point is the qemit! macro. It returns a proc_macro2::TokenStream.

Basic Quoting

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.

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:

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:

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:

at your option.

Cheers, RazkarStudio.

© 2026 RazkarStudio. All rights reserved.