Struct sapper_std::Context
[−]
pub struct Context { /* fields omitted */ }
The struct that holds the context of a template rendering.
Light wrapper around a BTreeMap
for easier insertions of Serializable
values
Methods
impl Context
fn new() -> Context
Initializes an empty context
fn add<T>(&mut self, key: &str, val: &T) where
T: Serialize,
T: Serialize,
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.add("number_users", 42);
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.add("a", 1); target.add("b", 2); let mut source = Context::new(); source.add("b", 3); source.add("d", 4); target.extend(source);
Trait Implementations
impl Clone for Context
impl Debug for Context
impl Default for Context
impl Serialize for Context
fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,