Skip to main content

Module debug

Module debug 

Source
Expand description

Debug formatting and printing for template expansions. Debug formatting utilities for macro expansions.

Provides a pipeline API for formatting generated TokenStreams into human-readable strings. Used internally by the debug attribute argument on #[zyn::element], #[zyn::pipe], #[zyn::derive], and #[zyn::attribute].

§Formats

  • Raw (always available) — calls TokenStream::to_string(), producing a flat single-line string with fully-qualified paths. No extra dependencies.

  • Pretty (requires the pretty feature) — parses the token stream into a syn::File and formats it with prettyplease, producing properly indented Rust code. Enable with:

    zyn = { version = "0.3", features = ["pretty"] }

§Usage

The [DebugExt] trait adds a .debug() method to proc_macro2::TokenStream, returning a [DebugTokens] builder with .raw() and .pretty() methods:

use zyn::debug::DebugExt;

let raw: String = tokens.debug().raw();

#[cfg(feature = "pretty")]
let pretty: String = tokens.debug().pretty();

§Macro integration

In attribute macros, add debug or debug = "pretty" to emit the generated code as a compiler note diagnostic. Requires ZYN_DEBUG to be set:

#[zyn::element(debug)]
fn greeting(name: syn::Ident) -> zyn::TokenStream { ... }

// ZYN_DEBUG="*" cargo build
// → note: zyn::element ─── Greeting
//         struct Greeting { pub name : syn :: Ident , } impl ...

Structs§

DebugTokens
Wraps a reference to a proc_macro2::TokenStream and provides formatting methods for debug output.

Traits§

DebugExt
Extension trait that adds .debug() to proc_macro2::TokenStream.