Skip to content

Documentation could suggest using std::sync::LazyLock instead of lazy_static #968

@Elrendio

Description

@Elrendio

Getting started documentation suggests to use lazy_static when it could suggest the more idiomatic way using std::sync::LazyLock (or OnceLock).

Changes

New version:

pub static TEMPLATES: Tera = std::sync::LazyLock::new(|| {
    let mut tera = match Tera::new("examples/basic/templates/**/*") {
        Ok(t) => t,
        Err(e) => {
            println!("Parsing error(s): {}", e);
            ::std::process::exit(1);
        }
    };
    tera.autoescape_on(vec![".html", ".sql"]);
    tera.register_filter("do_nothing", do_nothing_filter);
    tera
});

Old Version:

lazy_static! {
    pub static ref TEMPLATES: Tera = {
        let mut tera = match Tera::new("examples/basic/templates/**/*") {
            Ok(t) => t,
            Err(e) => {
                println!("Parsing error(s): {}", e);
                ::std::process::exit(1);
            }
        };
        tera.autoescape_on(vec![".html", ".sql"]);
        tera.register_filter("do_nothing", do_nothing_filter);
        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