minijinja::value

Trait ArgType

Source
pub trait ArgType<'a> {
    type Output;
}
Expand description

A trait implemented by all filter/test argument types.

This trait is used by FunctionArgs. It’s implemented for many common types that are typically passed to filters, tests or functions. It’s implemented for the following types:

The type is also implemented for optional values (Option<T>) which is used to encode optional parameters to filters, functions or tests. Additionally it’s implemented for Rest<T> which is used to encode the remaining arguments of a function call.

§Notes on Borrowing

Note on that there is an important difference between String and &str: the former will be valid for all values and an implicit conversion to string via ToString will take place, for the latter only values which are already strings will be passed. A compromise between the two is Cow<'_, str> which will behave like String but borrows when possible.

Byte slices will borrow out of values carrying bytes or strings. In the latter case the utf-8 bytes are returned.

There are also further restrictions imposed on borrowing in some situations. For instance you cannot implicitly borrow out of sequences which means that for instance Vec<&str> is not a legal argument.

§Notes on State

When &State is used, it does not consume a passed parameter. This means that a filter that takes (&State, String) actually only has one argument. The state is passed implicitly.

Required Associated Types§

Source

type Output

The output type of this argument.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'a> ArgType<'a> for &str

Source§

type Output = &'a str

Source§

impl<'a> ArgType<'a> for &[u8]

Source§

type Output = &'a [u8]

Source§

impl<'a> ArgType<'a> for &[Value]

Source§

type Output = &'a [Value]

Source§

impl<'a> ArgType<'a> for Cow<'_, str>

Source§

type Output = Cow<'a, str>

Source§

impl<'a> ArgType<'a> for bool

Source§

impl<'a> ArgType<'a> for char

Source§

impl<'a> ArgType<'a> for f32

Source§

impl<'a> ArgType<'a> for f64

Source§

impl<'a> ArgType<'a> for i8

Source§

impl<'a> ArgType<'a> for i16

Source§

impl<'a> ArgType<'a> for i32

Source§

impl<'a> ArgType<'a> for i64

Source§

impl<'a> ArgType<'a> for i128

Source§

impl<'a> ArgType<'a> for u8

Source§

impl<'a> ArgType<'a> for u16

Source§

impl<'a> ArgType<'a> for u32

Source§

impl<'a> ArgType<'a> for u64

Source§

impl<'a> ArgType<'a> for u128

Source§

impl<'a> ArgType<'a> for usize

Source§

impl<'a> ArgType<'a> for String

Source§

impl<'a> ArgType<'a> for Arc<str>

Source§

impl<'a, T: ArgType<'a>> ArgType<'a> for Option<T>

Source§

type Output = Option<<T as ArgType<'a>>::Output>

Source§

impl<'a, T: ArgType<'a, Output = T>> ArgType<'a> for Vec<T>

Source§

impl<'a, T: Object + 'static> ArgType<'a> for &T

Source§

impl<'a, T: Object + 'static> ArgType<'a> for Arc<T>

Implementors§

Source§

impl<'a> ArgType<'a> for &State<'_, '_>

Source§

type Output = &'a State<'a, 'a>

Source§

impl<'a> ArgType<'a> for &Value

Source§

impl<'a> ArgType<'a> for DynObject

Source§

impl<'a> ArgType<'a> for Kwargs

Source§

impl<'a> ArgType<'a> for Value

Source§

impl<'a, T: Deserialize<'a>> ArgType<'a> for ViaDeserialize<T>

Source§

impl<'a, T: ArgType<'a, Output = T>> ArgType<'a> for Rest<T>