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:
- eval state:
&State
(see below for notes) - unsigned integers:
u8
,u16
,u32
,u64
,u128
,usize
- signed integers:
i8
,i16
,i32
,i64
,i128
- floats:
f32
,f64
- bool:
bool
- string:
String
,&str
,Cow<'_, str>
,char
- bytes:
&[u8]
- values:
Value
,&Value
- vectors:
Vec<T>
- objects:
DynObject
,Arc<T>
,&T
(whereT
is anObject
) - serde deserializable:
ViaDeserialize<T>
- keyword arguments:
Kwargs
- leftover arguments:
Rest<T>
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.