Skip to main content

TextFunction

Struct TextFunction 

Source
pub struct TextFunction { /* private fields */ }
Expand description

Tera template function that can localize a message. It contains an Arc shared reference of fluent bundle.

Usage assuming it was registered as text:

{{ text(id="hello-wold", lang="en", examplearg=foo, n=3, bla=true) }}

How types that will be handled:

  • null: will be ignored
  • string: will be passed to the fluent template as is
  • number: will be passed as is with default settings (for now), errors if the number isn’t representable as f64.
  • bool: will be passed as the strings true and false
  • object|array: will throw a type error

Implementations§

Source§

impl TextFunction

Source

pub fn new( language_engine: Arc<LanguageEngine>, context_getter: TextFunctionContextGetter, ) -> Self

Create a new TextFunction using a LanguageEngine that can be shared between multiple data structures.

The language_getter is a callback that returns the language to use if the lang argument of the text function is not set. See TextFunctionContextGetter for a more detailed explanation.

Trait Implementations§

Source§

impl Function<Result<Value, Error>> for TextFunction

Source§

fn call(&self, args: Kwargs, state: &State<'_>) -> TeraResult<Value>

The function type definition
Source§

fn is_safe(&self) -> bool

Whether the current function’s output should be treated as safe, defaults to false Only needs to be defined if the filter returns a string

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more