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) -> SelfCreates 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) -> boolWhether 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
escapefn 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
mapthat need to apply other filters.
Trait Implementations
impl<'tera> Debug for State<'tera>
fn fmt(&self, f: &mut Formatter<'_>) -> Result