template!() { /* proc-macro */ }Expand description
Build a moxy::token::TokenStream at runtime from a template, in the style
of quote!.
The macro expands to a block that constructs and returns a TokenStream.
Interpolations and control flow are evaluated against the surrounding scope:
{{ expr }}splices the runtime value ofexpr(viamoxy::token::ToTokens), preserving its source spans.@for (binding in iter) { … },@if (cond) { … } @else { … }, and@match (expr) { pat => { … }, … }run as real control flow, appending to the output as they execute.
§Example
ⓘ
let items = vec!["a", "b", "c"];
let tokens = template! {
@for (item in items) {
{{ item }}
}
};
assert_eq!(tokens.to_string(), "a b c");A malformed template produces a span-targeted compile error.