Struct Context
struct Context { ... }
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 insert<T: Serialize + ?Sized, S: Into<String>>(self: &mut Self, key: S, val: &T)Converts the
valparameter toValueand insert it into the context.Panics if the serialization fails.
# use Context; let mut context = new; context.insert;fn try_insert<T: Serialize + ?Sized, S: Into<String>>(self: &mut Self, key: S, val: &T) -> TeraResult<()>Converts the
valparameter toValueand insert it into the context.Returns an error if the serialization fails.
# use Context; # ; # # let user = CannotBeSerialized; let mut context = new; // user is an instance of a struct implementing `Serialize` if let Err = context.try_insertfn extend(self: &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 into_json(self: Self) -> ValueConverts the context to a
serde_json::Valueconsuming the context.fn from_value(obj: Value) -> TeraResult<Self>Takes a serde-json
Valueand convert it into aContextwith no overhead/cloning.fn from_serialize<impl Serialize: Serialize>(value: impl Serialize) -> TeraResult<Self>Takes something that impl Serialize and create 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 get(self: &Self, index: &str) -> Option<&Value>Returns the value at a given key index.
fn remove(self: &mut Self, index: &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 contains_key(self: &Self, index: &str) -> boolChecks if a value exists at a specific index.
impl Clone for Context
fn clone(self: &Self) -> Context
impl Debug for Context
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Default for Context
fn default() -> Context
impl Freeze for Context
impl PartialEq for Context
fn eq(self: &Self, other: &Context) -> bool
impl RefUnwindSafe for Context
impl Send for Context
impl StructuralPartialEq for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin for Context
impl UnwindSafe for Context
impl<T> Any for Context
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Context
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Context
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Context
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Context
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Pointable for Context
unsafe fn init(init: <T as Pointable>::Init) -> usizeunsafe fn deref<'a>(ptr: usize) -> &'a Tunsafe fn deref_mut<'a>(ptr: usize) -> &'a mut Tunsafe fn drop(ptr: usize)
impl<T> ToOwned for Context
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for Context
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Context
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Context
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>
impl<V, T> VZip for Context
fn vzip(self: Self) -> V