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

Templates

The zyn! macro is the core of zyn. It accepts a template and returns a zyn::TokenStream:

let tokens: zyn::TokenStream = zyn! {
    pub struct {{ name }} {
        @for (field in fields.iter()) {
            {{ field.ident }}: {{ field.ty }},
        }
    }
};

Everything outside {{ }} and @ directives passes through as literal tokens, just like quote!.

Syntax Overview

SyntaxPurpose
{{ expr }}Interpolation — insert any ToTokens value
{{ expr | pipe }}Pipes — transform values (case conversion, formatting)
@if / @for / @matchControl flow — conditionals, loops, pattern matching
@element_name(props)Element invocation — reusable template components