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
prettyfeature) — parses the token stream into asyn::Fileand formats it withprettyplease, producing properly indented Rust code. Enable with:zyn = { version = "0.4", 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 with options) to emit the generated
code as a compiler note diagnostic. Requires ZYN_DEBUG to be set:
#[zyn::element(debug)] // body only, raw
#[zyn::element(debug(pretty))] // body only, pretty-printed
#[zyn::element(debug(full))] // full struct + impl, raw
#[zyn::element(debug(pretty, full))] // full struct + impl, pretty-printed
#[zyn::element(debug(name = "Foo"))] // inject prop value, raw
#[zyn::element(debug(pretty, name = "Foo"))] // inject prop value, pretty-printed
fn greeting(name: syn::Ident) -> zyn::TokenStream { ... }
// ZYN_DEBUG="*" cargo build
// → note: zyn::element ─── Greeting
//
// fn {{ name }}() {}Structs§
- Debug
Tokens - Wraps a reference to a
proc_macro2::TokenStreamand provides formatting methods for debug output.
Traits§
- Debug
Ext - Extension trait that adds
.debug()toproc_macro2::TokenStream.