#codegen #proc-macro #template

no-std genco

A whitespace-aware quasiquoter for beautiful code generation

109 releases

0.19.0 Oct 21, 2025
0.18.0 Jul 21, 2025
0.17.10 Nov 13, 2024
0.17.9 May 18, 2024
0.1.11 Nov 22, 2017

#16 in Template engine

Download history 17630/week @ 2025-10-22 18165/week @ 2025-10-29 23112/week @ 2025-11-05 17033/week @ 2025-11-12 27610/week @ 2025-11-19 20515/week @ 2025-11-26 24355/week @ 2025-12-03 29669/week @ 2025-12-10 24110/week @ 2025-12-17 22424/week @ 2025-12-24 17513/week @ 2025-12-31 28036/week @ 2026-01-07 26282/week @ 2026-01-14 24257/week @ 2026-01-21 20534/week @ 2026-01-28 17886/week @ 2026-02-04

94,794 downloads per month
Used in 104 crates (33 directly)

MIT/Apache

260KB
5.5K SLoC

genco

github crates.io docs.rs build status

A whitespace-aware quasiquoter for beautiful code generation.

Central to genco are the quote! and quote_in! procedural macros which ease the construction of token streams.

This project solves the following language-specific concerns:

  • Imports — Generates and groups import statements as they are used. So you only import what you use, with no redundancy. We also do our best to solve namespace conflicts.

  • String Quoting — genco knows how to quote strings. And can even interpolate values into the quoted string if it's supported by the language.

  • Structural Indentation — The quoter relies on intuitive whitespace detection to structurally sort out spacings and indentation. Allowing genco to generate beautiful readable code with minimal effort. This is also a requirement for generating correctly behaving code in languages like Python where indentation is meaningful.

  • Language Customization — Building support for new languages is a piece of cake with the help of the impl_lang! macro.


To support line changes during whitespace detection, we depend on span information which was made available in Rust 1.88. Before that, we rely on a nightly proc_macro_span feature to work.

Prior to this version of Rust if you want fully functional whitespace detection you must build and run projects using genco with a nightly compiler. This is important for whitespace-sensitive languages like python.

You can try the difference between:

cargo run --example rust

And:

cargo +nightly run --example rust

Supported Languages

The following are languages which have built-in support in genco.

Is your favorite language missing? Open an issue!

You can run one of the examples by:

cargo +nightly run --example rust

Rust Example

The following is a simple program producing Rust code to stdout with custom configuration:

use genco::prelude::*;

let hash_map = rust::import("std::collections", "HashMap");

let tokens: rust::Tokens = quote! {
    fn main() {
        let mut m = $hash_map::new();
        m.insert(1u32, 2u32);
    }
};

println!("{}", tokens.to_file_string()?);

This would produce:

use std::collections::HashMap;

fn main() {
    let mut m = HashMap::new();
    m.insert(1u32, 2u32);
}

Dependencies

~290–710KB
~16K SLoC