Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Debugging with debug!

zyn::debug! is a drop-in replacement for zyn! that prints what the template produces, then returns the same tokens. Use it to see exactly what code your template generates.

Basic Usage

let tokens = zyn::debug! {
    struct {{ name }} {
        @for (field in fields.iter()) {
            {{ field.ident }}: {{ field.ty }},
        }
    }
};
zyn::debug! ─── pretty
struct MyStruct {
    name: String,
    age: u32,
}

Modes

Specify a mode before => to control the output format:

pretty (default)

Shows the final Rust code your template produces — the actual output, formatted with indentation.

zyn::debug! { pretty =>
    @if (is_pub) { pub }
    fn {{ name | snake }}() {}
}

When no mode is specified, pretty is used:

zyn::debug! {
    fn {{ name }}() {}
}

The output appears on stderr at runtime (when the proc macro executes), so it’s visible in cargo build and cargo test output.

raw

Shows the expansion code — the token-building machinery that zyn! generates behind the scenes. Emitted as a compile-time diagnostic (zero runtime cost).

zyn::debug! { raw =>
    struct {{ name }} {}
}
note: zyn::debug! ─── raw

{
    let mut output = TokenStream::new();
    output.extend(quote!(struct));
    ToTokens::to_tokens(&(name), &mut output);
    output.extend(quote!({}));
    output
}

The output is cleaned up for readability — __zyn_ts_0 becomes output, fully-qualified paths are simplified.

ast

Shows the parsed template structure — which AST nodes the parser created. Emitted as a compile-time diagnostic.

zyn::debug! { ast =>
    @if (is_pub) { pub }
    struct {{ name }} {}
}
note: zyn::debug! ─── ast

Template [
  At(If)
  Tokens("struct")
  Interp { ... }
  Tokens("{}")
]