pub struct WebContext { /* 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>(&mut self, key: &str, val: &T)
pub fn insert<T>(&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);
Trait Implementations§
Source§impl Serialize for Context
impl Serialize for Context
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl StructuralPartialEq for Context
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnwindSafe for Context
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more