~homeworkprod/orgatalk-discord-orgateams

b998846570d4caee049d852364fb0c353421f659 — Jochen Kupperschmidt a month ago 4f15b96
Remove dependency on lazy_static
4 files changed, 8 insertions(+), 7 deletions(-)

M CHANGELOG.md
M Cargo.lock
M Cargo.toml
M src/templating.rs
M CHANGELOG.md => CHANGELOG.md +2 -0
@@ 15,6 15,8 @@

- Updated ureq to v2.9.7.

- Removed dependency on lazy\_static.


## 0.3.0 (2022-07-06)


M Cargo.lock => Cargo.lock +0 -1
@@ 386,7 386,6 @@ version = "0.4.0"
dependencies = [
 "anyhow",
 "clap",
 "lazy_static",
 "multimap",
 "serde",
 "serde_json",

M Cargo.toml => Cargo.toml +0 -1
@@ 11,7 11,6 @@ keywords = ["discord"]
[dependencies]
anyhow = "1.0"
clap = { version = "4.5.4", default-features = false, features = ["cargo", "derive", "error-context", "help", "std", "usage", "wrap_help"] }
lazy_static = "1.4.0"
multimap = "0.10.0"
serde = { version = "1", features = ["derive"] }
serde_json = "1.0"

M src/templating.rs => src/templating.rs +6 -5
@@ 4,21 4,22 @@
 */

use anyhow::Result;
use lazy_static::lazy_static;
use std::io::Write;
use std::sync::OnceLock;
use tera::{Context, Tera};

use crate::model::Role;

lazy_static! {
    static ref TERA: Tera = {
fn get_tera() -> &'static Tera {
    static TERA: OnceLock<Tera> = OnceLock::new();
    TERA.get_or_init(|| {
        let mut tera = Tera::default();
        tera.add_raw_template("index.html", include_str!("templates/index.html"))
            .unwrap();
        tera.add_raw_template("index.txt", include_str!("templates/index.txt"))
            .unwrap();
        tera
    };
    })
}

/// Render roles as HTML representation.


@@ 37,7 38,7 @@ fn render(template_name: &str, roles: Vec<Role>, writer: impl Write) -> Result<(
    let mut context = Context::new();
    context.insert("roles", &roles);

    TERA.render_to(template_name, &context, writer)?;
    get_tera().render_to(template_name, &context, writer)?;

    Ok(())
}