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.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§
- 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.