Expand description
Builder patterns for fluent template construction.
This module provides builder patterns for TronTemplate and TronRef
that allow for more ergonomic and fluent template creation with method chaining.
§Examples
Using the template builder:
use tron::TronTemplateBuilder;
use std::collections::HashMap;
let mut values = HashMap::new();
values.insert("name", "greet");
values.insert("body", "println!(\"Hello, World!\");");
let template = TronTemplateBuilder::new()
.content("fn @[name]@() {\n @[body]@\n}")
.set("name", "greet")
.set("body", "println!(\"Hello, World!\");")
.build()
.unwrap();
let result = template.render().unwrap();Using the template reference builder:
use tron::{TronTemplateBuilder, TronRefBuilder};
let template_ref = TronRefBuilder::new()
.content("fn main() {\n @[body]@\n}")
.dependency("serde = \"1.0\"")
.dependency("tokio = \"1.0\"")
.set("body", "println!(\"Hello from builder!\");")
.build()
.unwrap();Structs§
- Tron
RefBuilder - Builder for creating
TronRefinstances with a fluent API. - Tron
Template Builder - Builder for creating
TronTemplateinstances with a fluent API.