Skip to content

Derive Clone for tera::Error #966

@jblachly

Description

@jblachly

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions