Struct Context
pub struct Context { /* private fields */ }
The struct that holds the context of a template rendering.
Light wrapper around a BTreeMap for easier insertions of Serializable
values
Implementations
impl Context
fn new() -> SelfInitializes an empty context
fn from_serialize<T: Serialize + ?Sized>(value: &T) -> TeraResult<Self>Takes something that implements Serialize and creates a context with it. Meant to be used if you have a hashmap or a struct and don't want to insert values one by one in the context.
fn insert<S: Into<Cow<'static, str>>, T: Serialize + ?Sized>(&mut self, key: S, val: &T)Converts the
valparameter toValueand insert it into the context. This can panic if the value cannot be serialised.# use Context; let mut context = new; context.insert;fn insert_value<S: Into<Cow<'static, str>>>(&mut self, key: S, val: Value)In case you already have a
Valueyou want to insertfn remove(&mut self, key: &str) -> Option<Value>Remove a key from the context, returning the value at the key if the key was previously inserted into the context.
fn extend(&mut self, source: Context)Appends the data of the
sourceparameter toself, overwriting existing keys. The source context will be dropped.# use Context; let mut target = new; target.insert; target.insert; let mut source = new; source.insert; source.insert; target.extend;fn contains_key(&self, key: &str) -> boolChecks if a value exists for given key.
fn get(&self, key: &str) -> Option<&Value>Returns the value at the given key
Trait Implementations
impl Clone for Context
fn clone(&self) -> Context
impl Debug for Context
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Default for Context
fn default() -> Context
impl PartialEq for Context
fn eq(&self, other: &Context) -> bool
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 UnsafeUnpin for Context
impl UnwindSafe for Context
Blanket Implementations
impl<T> Any for Context
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Context
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Context
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Context
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Context
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Context
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for Context
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Context
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Context
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>