Trait django_query::filtering::Operator
source · [−]pub trait Operator<T> {
fn apply(&self, value: &T) -> bool;
fn empty_collection(&self) -> bool { ... }
fn null_option(&self) -> bool { ... }
}
Expand description
Take a single simple value and produce a true/false result.
Operators are generally applied by Operable types, so the
operators themselves can be naive with respect to things like
Option and collections. For operators that need to know about
special cases, there are the inelegant get-out functions
empty_collection() and
null_option() which can be
implemented. Both return false
by default.
The standard Django operators are in the
operators module. Examples are
eq
,
in
,
contains
and so forth.
Required methods
Provided methods
fn empty_collection(&self) -> bool
fn empty_collection(&self) -> bool
Return a value for this operator when applied to an empty
collection. Implicitly, operators are distributed over
collections with any
semantics, so that any true
result
means the collection evaluates to true
. The default
behaviour for this method is to return false
, which is
consistent with those semantics.
fn null_option(&self) -> bool
fn null_option(&self) -> bool
Return a value for this operator when applied to a None
value wrapping its target type (e.g. for an operator on T, we
are determining the behaviour on Optionfalse
for None
(e.g. `isnull).