This is also sort of a wishlist item for v2 (#637) but OTOH could be added to existing version without breaking API compat.
Use case: obtaining a pre-parsed Tera instance in multiple functions throughout a module.
pub static TEMPLATES_PATH: &'static str = "templates/register/**/*.html";
static TEMPLATES: LazyLock<Result<Tera, tera::Error>> = LazyLock::new(|| {
Tera::new(TEMPLATES_PATH).map_err(|e| {
tracing::error!("Template parsing error(s): {}", e);
e
})
});
pub fn tera_instance() -> Result<Tera, tera::Error> {
let tera = if cfg!(debug_assertions) {
// in dev only allow hot reloading
Tera::new(TEMPLATES_PATH)
} else {
TEMPLATES.clone()
};
tera
}
This is also sort of a wishlist item for v2 (#637) but OTOH could be added to existing version without breaking API compat.
Use case: obtaining a pre-parsed Tera instance in multiple functions throughout a module.