Crate tour

Source
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 to TemplDisplay.
Display
Wrap fmt::Display to TemplDisplay.
Escape
Wrap TemplWrite to escape input.
FmtTemplWrite
Wrap std::fmt::Write to TemplWrite.
IoTemplWrite
Wrap std::io::Write to TemplWrite.
TemplWriteFmt
Wrap TemplWrite to std::fmt::Write.
TemplWriteIo
Wrap TemplWrite to std::io::Write.

Enums§

Error
An error that can occur during rendering.

Traits§

TemplDisplay
Analogous to std::fmt::Display without the Formatter.
TemplWrite
Analogous to std::fmt::Write without the Formatter.
Template
A template content.

Type Aliases§

Result
Result alias for Error.