qemit 0.1.0

A minimalist quasi-quoting library using declarative macros
Documentation
<div align="center">

# qemit

[![Rust Version](https://img.shields.io/badge/rustc-2024%20edition-blue.svg)](https://doc.rust-lang.org/edition-guide/rust-2024/)
[![Crates.io Version](https://img.shields.io/crates/v/qemit)](https://crates.io/crates/qemit)
[![docs.rs](https://img.shields.io/docsrs/qemit)](https://docs.rs/qemit)
[![License MIT](https://img.shields.io/crates/l/qemit)](https://codeberg.org/razkar/qemit/src/branch/main/LICENSE-MIT)
[![License Apache-2.0](https://img.shields.io/crates/l/farben)](https://codeberg.org/razkar/qemit/src/branch/main/LICENSE-APACHE)
[![Crates.io Downloads](https://img.shields.io/crates/d/qemit)](https://crates.io/crates/qemit)
[![Deps.rs](https://deps.rs/repo/codeberg/razkar/qemit/status.svg)](https://deps.rs/repo/codeberg/razkar/qemit)
[![Maintenance](https://img.shields.io/badge/maintenance-actively--developed-brightgreen)](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.