alethea
Overview
alethea is a Rust templating approach designed to keep templates simple,
expressive, and fully aligned with the Rust language itself.
Instead of introducing a new syntax, it allows you to write templates using native Rust constructs, reducing cognitive overhead and increasing flexibility.
Goals
-
Eliminate
std::string-style complexity:- Avoid manual string building (
push_str, etc.) in most cases. - Keep templates focused on structure rather than concatenation.
- Avoid manual string building (
-
Reduce the learning curve and use Rust directly inside templates:
- No new syntax to learn—just Rust.
- Avoid limitations commonly found in traditional template engines.
- Reuse existing powerful Rust features like
format!and standard library utilities, including padding and alignment. - Behavior should be predictable if you already know Rust.
-
Ensure compile-time template safety:
- Catch errors early during compilation.
- Enable more reliable and maintainable templates.
-
Treat input data as read-only:
- Templates should not modify their inputs.
- Any attempt to mutate inputs will fail at compile time.
-
Keep composition simple:
- Provide clear and straightforward template inheritance.
- Support nested templates for better structure and reuse.
Quick Start
Add alethea to your Cargo.toml:
[]
= "0.1.0"
HTML Template Definition Example
use ;
new_template!
/*
Usage example :
let animal_html = animals_html!(animals: animals);
// Write the string directly to the file, panic on error
fs::write(
"examples/htmlgen_basic/output_html/animals.html",
&animal_html,
)
.unwrap();
*/
Examples
For more complete and advanced use cases (including template inheritance), check the repository.
The examples/ directory contains small projects demonstrating
how to use alethea in real scenarios, including:
- Web frameworks like Axum, Actix, and Rocket
- Standalone HTML rendering
- File generation
Running an example