Textus
Compile-time validated folder-based templating for Rust, powered by a derive macro.
Textus walks a directory of template files at compile time, extracts {{ var }} placeholders,
and checks them against your struct fields — catching mismatches before your code ever runs.
Usage
Given a templates/ folder:
templates/
├── greeting.txt → Hello, {{ name }}!
└── config/app.toml → title = "{{ name }}"
Define a template struct:
use Template;
Validation modes
Set the mode with #[template(path = "...", mode = "strict")].
| Mode | Template vars must exist as fields | Fields must appear in templates |
|---|---|---|
"default" |
✓ | ✗ |
"strict" |
✓ | ✓ |
"lenient" |
✗ | ✗ |
How it works
- The derive macro runs at compile time, reading and parsing every file under
path. - Variables (
{{ var }}) are matched against the struct's named fields. - Mismatches produce clear
compile_error!messages with context. - Templates without variables return
Cow::Borrowed(zero allocation); dynamic ones useformat!and returnCow::Owned. - File changes are tracked via
include_bytes!, socargorebuilds automatically when templates change.