Skip to main content

prosaic_template_compiled

Macro prosaic_template_compiled 

Source
prosaic_template_compiled!() { /* proc-macro */ }
Expand description

Compile-time compiled template rendering function.

Parses the template at compile time and emits a specialized render function that avoids the runtime parsing pipeline. Suitable for tight loops with known, simple templates.

Returns a fn(&prosaic_core::Context) -> String as a block expression.

§Supported syntax

Only bare slot references are supported: {key} and literal text. The following will produce a compile error:

  • Pipes: {key|capitalize}
  • Conditional sections: {?key}...{/?}
  • Partial inclusions: {>name}

For templates requiring any of the above, use the runtime engine directly.

§Example

use prosaic_derive::prosaic_template_compiled;
use prosaic_core::{Context, Value};

let render = prosaic_template_compiled!("The class {name} was modified");
let mut ctx = Context::new();
ctx.insert("name", Value::String("Foo".into()));
assert_eq!(render(&ctx), "The class Foo was modified");