Struct StringInput
pub struct StringInput<'a> { /* private fields */ }
A Value::String with some helpers around it for safety The main usage is to use it as the value or string parameters for filters operating on strings (for example a filter block)
Examples
use tera::{Tera, Kwargs, State, StringInput};
let mut tera = Tera::default();
tera.register_filter("is_safe", |x: StringInput, _: Kwargs, _: &State| x.is_safe());
tera.register_filter("uppercase", |x: StringInput, _: Kwargs, _: &State| x.inherit_safety(x.as_str().to_uppercase()));
Implementations
impl<'a> StringInput<'a>
fn into_value(self) -> ValueReturns this StringInput as a Value, with the correct safety flag
fn as_str(&self) -> &'a strReturns the actual string
fn is_safe(&self) -> booltrueif the original value was marked safefn inherit_safety(&self, output: String) -> ValueReturns a new Value for the given output, inheriting the StringInput safety This should only be used when the new output is taken directly from the StringInput and there's no deletion/decoding etc that could make the output unsafe. If it's misused, it could mark some unsafe strings as safe.
fn rendered(&self, state: &State<'_>) -> TeraResult<Cow<'_, str>>Render the current string as if it was used in
{{ }}context, taking into account its own safety flag as well as whether autoescaping is currently enabled.
Trait Implementations
impl<'a> Debug for StringInput<'a>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<'k> ArgFromValue<'k> for StringInput<'_>
type Output = StringInput<'k>;fn from_value(value: &'k Value) -> TeraResult<Self::Output>