typlate
A Rust library for type-safe string templates with compile-time validation.
Installation
Add to your Cargo.toml:
[]
= { = "0.2", = ["full"] }
Quick Start
use ;
Template Syntax
- Variables are enclosed in curly braces:
{variable_name} - To include literal braces, double them:
{{for{and}}for} - Variable names must match the field names of the target type
Serde Support
With the serde feature enabled, templates can be serialized and deserialized using serde:
use ;
use ;
let json = r#"{"foo": "Value is {value}"}"#;
let messages: Messages = from_str.unwrap;
let data = Data ;
assert_eq!;
Error Handling
Template parsing will fail if:
- Variable names don't match any field in the target type
- Brackets are not properly matched