Skip to main content

trillium_handlebars/
assigns.rs

1use serde::Serialize;
2use serde_json::Value;
3use std::{
4    borrow::Cow,
5    collections::HashMap,
6    ops::{Deref, DerefMut},
7};
8
9/**
10A struct for accumulating key-value data for use in handlebars
11templates. The values can be any type that is serde serializable
12*/
13#[derive(Default, Serialize, Debug)]
14pub struct Assigns(HashMap<Cow<'static, str>, Value>);
15
16impl Deref for Assigns {
17    type Target = HashMap<Cow<'static, str>, Value>;
18
19    fn deref(&self) -> &Self::Target {
20        &self.0
21    }
22}
23
24impl DerefMut for Assigns {
25    fn deref_mut(&mut self) -> &mut Self::Target {
26        &mut self.0
27    }
28}