pub struct Context { /* private fields */ }
Expand description
The struct that holds the context of a template rendering.
Light wrapper around a BTreeMap
for easier insertions of Serializable
values
Implementations§
source§impl Context
impl Context
sourcepub fn insert<T: Serialize + ?Sized>(&mut self, key: &str, val: &T)
pub fn insert<T: Serialize + ?Sized>(&mut self, key: &str, val: &T)
Converts the val
parameter to Value
and insert it into the context
ⓘ
let mut context = Context::new();
// user is an instance of a struct implementing `Serialize`
context.insert("number_users", 42);
sourcepub fn extend(&mut self, source: Context)
pub fn extend(&mut self, source: Context)
Appends the data of the source
parameter to self
, overwriting existing keys.
The source context will be dropped.
ⓘ
let mut target = Context::new();
target.insert("a", 1);
target.insert("b", 2);
let mut source = Context::new();
source.insert("b", 3);
source.insert("d", 4);
target.extend(source);