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) -> Value

Returns this StringInput as a Value, with the correct safety flag

fn as_str(&self) -> &'a str

Returns the actual string

fn is_safe(&self) -> bool

true if the original value was marked safe

fn inherit_safety(&self, output: String) -> Value

Returns 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>

Auto Trait Implementations

impl<'a> Freeze for StringInput<'a>

impl<'a> RefUnwindSafe for StringInput<'a>

impl<'a> Send for StringInput<'a>

impl<'a> Sync for StringInput<'a>

impl<'a> Unpin for StringInput<'a>

impl<'a> UnsafeUnpin for StringInput<'a>

impl<'a> UnwindSafe for StringInput<'a>

Blanket Implementations

impl<T> Any for StringInput<'a> where T: 'static + ?Sized,

impl<T> Borrow<T> for StringInput<'a> where T: ?Sized,

impl<T> BorrowMut<T> for StringInput<'a> where T: ?Sized,

impl<T> From<T> for StringInput<'a>

impl<T, U> Into<U> for StringInput<'a> where U: From<T>,

impl<T, U> TryFrom<U> for StringInput<'a> where U: Into<T>,

impl<T, U> TryInto<U> for StringInput<'a> where U: TryFrom<T>,