Skip to content

Derive Clone for tera::Error #966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jblachly opened this issue Apr 14, 2025 · 5 comments
Open

Derive Clone for tera::Error #966

jblachly opened this issue Apr 14, 2025 · 5 comments

Comments

@jblachly
Copy link

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
}
@Keats
Copy link
Owner

Keats commented Apr 15, 2025

The issue is always io::Error which cannot be cloned

@jblachly
Copy link
Author

I may be misunderstanding -- the Tera ErrorKind enum wraps std::io::ErrorKind, which is cloneable.

@Keats
Copy link
Owner

Keats commented Apr 16, 2025

Ah true for some reasons i thought it was io:Error. Tera2 already has Clone implemented: https://github.com/Keats/tera2/blob/master/tera/src/errors.rs#L35

@jblachly
Copy link
Author

Didn't even know about Tera2, thanks!

@Keats
Copy link
Owner

Keats commented Apr 16, 2025

It's a WIP working pretty well already and with some experiments like Keats/tera2#51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants