Skip to main content

Crate moxy_template

Crate moxy_template 

Source
Expand description

§Moxy templates

Procedural macros for runtime token templates and identifier pasting.

§Template syntax

template! returns a moxy::token::TokenStream. {{ expr }} emits a value implementing moxy::token::ToTokens; @for, @if/@else, and @match evaluate ordinary Rust control flow while building the stream.

ⓘ
let fields = ["id", "name"];
let tokens = moxy::template! {
    struct User { @for (field in fields) { {{ field }}: String, } }
};

paste! instead joins tokens inside {{ ... }} into an identifier in declaration position, such as fn {{ get_ value }}() {}.

Macros§

paste
Concatenates the tokens inside each {{ ... }} marker into a single identifier at compile time, passing all other tokens through unchanged.
template
Build a moxy::token::TokenStream at runtime from a template, in the style of quote!.