Struct State

pub struct State<'tera> { /* private fields */ }

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

impl<'t> State<'t>

fn new(context: &'t Context) -> Self

Creates a new state from a Context. Public since it's needed to test filters/fns/tests but there are no filters registered to it.

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.

fn autoescaping_enabled(&self) -> bool

Whether autoescaping is enabled for the current content

fn escape_if_needed(&self, value: &Value) -> TeraResult<String>

Escapes a string using the escape fn defined in the Tera struct, but only if the current content needs escaping and is not already safe. If you need unconditional escaping, use escape

fn escape(&self, input: &str) -> TeraResult<String>

Escapes a string using the escape fn defined in the Tera struct

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

impl<'tera> Debug for State<'tera>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Auto Trait Implementations

impl<'tera> !RefUnwindSafe for State<'tera>

impl<'tera> !UnwindSafe for State<'tera>

impl<'tera> Freeze 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>

Blanket Implementations

impl<T> Any for State<'tera> where T: 'static + ?Sized,

impl<T> Borrow<T> for State<'tera> where T: ?Sized,

impl<T> BorrowMut<T> for State<'tera> where T: ?Sized,

impl<T> From<T> for State<'tera>

impl<T, U> Into<U> for State<'tera> where U: From<T>,

impl<T, U> TryFrom<U> for State<'tera> where U: Into<T>,

impl<T, U> TryInto<U> for State<'tera> where U: TryFrom<T>,