Expand description
§Tour Template
Tour Template is a compile-time templating library with support for runtime reload.
§Runtime Reload
Given type with Template derive macro:
ⓘ
// main.rs
use tour::Template;
#[derive(Template)]
#[template(path = "index.html")]
struct Tasks {
tasks: Vec<String>,
}
let result = Tasks { tasks: vec![] }.render().unwrap();
println!("{result}");Templates are searched from templates directory from project root by default, so above
example will search for templates/index.html.
<!-- templates/index.html -->
{{ for task in tasks }}
Task: {{ task.get(1..6) }}
{{ else }}
No Tasks
{{ endfor }}In debug mode, changing non expression like No Tasks in the source file, will
change the output with the new content on the next render without recompiling.
Note that changing expression like {{ for task in tasks }} still requires recompile. An
attempt to render it without recompile, will change nothing and may result in error.
This is still better than require to recompile on every small changes. In practice, quick changes iteration is used for style changes.
Re-exports§
pub use tour_core::Parser;pub use tour_core::StaticVisitor;pub use tour_macros::Template;
Structs§
- Debug
- Wrap
fmt::DebugtoTemplDisplay. - Display
- Wrap
fmt::DisplaytoTemplDisplay. - Escape
- Wrap
TemplWriteto escape input. - FmtTempl
Write - Wrap
std::fmt::WritetoTemplWrite. - IoTempl
Write - Wrap
std::io::WritetoTemplWrite. - Templ
Write Fmt - Wrap
TemplWritetostd::fmt::Write. - Templ
Write Io - Wrap
TemplWritetostd::io::Write.
Enums§
- Error
- An error that can occur during rendering.
Traits§
- Templ
Display - Analogous to
std::fmt::Displaywithout theFormatter. - Templ
Write - Analogous to
std::fmt::Writewithout theFormatter. - Template
- A template content.