pub struct State<'tera> { /* private fields */ }Expand description
The state of the interpreter. We pass it around rather than put it on the VM to avoid multiple borrow issues when dealing with inheritance.
Implementations§
Source§impl<'t> State<'t>
impl<'t> State<'t>
Sourcepub fn new(context: &'t Context) -> Self
pub fn new(context: &'t Context) -> Self
Creates a new state from a Context.
Public since it’s needed to test filters/fns/tests.
Sourcepub fn get<T>(&self, name: &str) -> TeraResult<Option<T>>where
for<'a> T: ArgFromValue<'a, Output = T>,
pub fn get<T>(&self, name: &str) -> TeraResult<Option<T>>where
for<'a> T: ArgFromValue<'a, Output = T>,
Get a variable from the context by name and convert it to the specified type.
Returns Ok(None) if the variable is not defined (undefined).
Returns an error if the variable exists but cannot be converted to the target type.
Sourcepub fn call_filter(
&self,
name: &str,
value: &Value,
kwargs: Kwargs,
) -> TeraResult<Value>
pub fn call_filter( &self, name: &str, value: &Value, kwargs: Kwargs, ) -> TeraResult<Value>
Call a filter by name. Used by filters like map that need to apply other filters.
Trait Implementations§
Auto Trait Implementations§
impl<'tera> Freeze for State<'tera>
impl<'tera> !RefUnwindSafe for State<'tera>
impl<'tera> Send for State<'tera>
impl<'tera> Sync for State<'tera>
impl<'tera> Unpin for State<'tera>
impl<'tera> UnsafeUnpin for State<'tera>
impl<'tera> !UnwindSafe for State<'tera>
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