Expand description
A template engine and framework for Rust procedural macros.
Zyn provides a zyn! template macro with interpolation, control flow, pipes,
reusable elements, and proc macro entry points — replacing the typical
syn + quote + heck + proc-macro-error stack with a single dependency.
§Example
ⓘ
use zyn::prelude::*;
zyn! {
impl {{ ident }} {
@for (field in fields.iter()) {
pub fn {{ field.ident | snake | ident:"get_{}" }}(&self) -> &{{ field.ty }} {
&self.{{ field.ident }}
}
}
}
}Modules§
- ast
- Template AST node types.
- case
- Case conversion utilities.
- debug
- Debug formatting and printing for template expansions.
- diagnostic
- Diagnostic accumulation and emission.
- extract
- Extractors for resolving values from proc macro input.
- ident
- Internal identifier generation for template expansion.
- meta
- Attribute argument parsing types.
- pipes
- Built-in pipe types for template value transforms.
- prelude
- The zyn prelude. Re-exports all built-in pipes, core traits, and proc macros.
- proc_
macro2 - github crates-io docs-rs
- quote
- github crates-io docs-rs
- syn
- github crates-io docs-rs
- template
- Template parsing and expansion.
- types
- Proc macro input types.
Macros§
- camel
- Converts a string or ident to camelCase.
- debug
- Expands a zyn template with diagnostic output for debugging.
- format_
ident - Formatting macro for constructing
Idents. - kebab
- Converts a string or ident to kebab-case.
- parse
- Parses tokens or string literals into a type. Wraps
syn::parse_strandsyn::parse2. - parse_
input - Parses a
proc_macro::TokenStreamin a proc macro entry point. Wrapssyn::parse_macro_input!. - pascal
- Converts a string or ident to PascalCase.
- screaming
- Converts a string or ident to SCREAMING_SNAKE_CASE.
- snake
- Converts a string or ident to snake_case.
- zyn
- Expands a zyn template into a
TokenStream.
Structs§
- Args
- A parsed list of attribute arguments.
- Attr
- Element extractor that resolves a
#[derive(Attribute)]struct from the input’s attributes. - Data
- Element extractor that pulls the
syn::Datafrom a derive input. - Diagnostic
- A structure representing a diagnostic message and associated children messages.
- Diagnostics
- An accumulator for compiler diagnostics (errors, warnings, notes, help messages).
- Extract
- Generic extractor wrapper — delegates to
T::from_input. - Fields
- Element extractor that pulls struct fields from the input.
- Span
- A region of source code, along with macro expansion information.
- Template
- A parsed template AST. Created by parsing template syntax via
syn::parse2::<Template>(tokens). - Token
Stream - An abstract stream of tokens, or more concretely a sequence of token trees.
- Variants
- Element extractor that pulls enum variants from the input.
Enums§
- Arg
- A single parsed attribute argument.
- Input
- The proc macro input context. Wraps either a
DeriveInputor anItem. - Level
- An enum representing a diagnostic level.
Traits§
- Expand
- Internal trait for AST node expansion. Not part of the public API.
- FromArg
- Converts a single
Arginto a typed value. - From
Data - Converts
syn::Datainto a specific data representation. - From
Fields - Converts
syn::Fieldsinto a specific fields representation. - From
Input - Extracts a value from the macro input context.
- Pipe
- Implemented by
#[zyn::pipe]types. Transforms a value in a pipe chain. - Render
- Implemented by
#[zyn::element]types. Renders the element with the givenInputcontext. - Span
Diagnostic Ext - Extension trait for
proc_macro2::Spanemulating the proc-macro diagnostic API on stable and nightly. - ToDiagnostics
- Conversion trait for types that can be turned into
Diagnostics. - ToTokens
- Types that can be interpolated inside a
quote!invocation.
Functions§
- closest_
match - Returns the closest matching string from
haystackif the edit distance is at most 3. Used for “did you mean?” suggestions in error messages. - levenshtein
- Computes the Levenshtein edit distance between two strings.
Type Aliases§
Attribute Macros§
- attribute
- Defines an attribute macro entry point that auto-parses the annotated item into
Input. - derive
- Defines a derive macro entry point that auto-parses
DeriveInputintoInput. - element
- Defines a reusable template component that generates a struct implementing
Render. - pipe
- Defines a custom pipe transform that generates a struct implementing
Pipe.
Derive Macros§
- Attribute
- Derives the
Attributetrait for typed attribute parsing from#[attr(...)]syntax.