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::Debug
toTemplDisplay
. - Display
- Wrap
fmt::Display
toTemplDisplay
. - Escape
- Wrap
TemplWrite
to escape input. - FmtTempl
Write - Wrap
std::fmt::Write
toTemplWrite
. - IoTempl
Write - Wrap
std::io::Write
toTemplWrite
. - Templ
Write Fmt - Wrap
TemplWrite
tostd::fmt::Write
. - Templ
Write Io - Wrap
TemplWrite
tostd::io::Write
.
Enums§
- Error
- An error that can occur during rendering.
Traits§
- Templ
Display - Analogous to
std::fmt::Display
without theFormatter
. - Templ
Write - Analogous to
std::fmt::Write
without theFormatter
. - Template
- A template content.