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

Apply this operator a single value, producing a true/false result.

Provided methods

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.

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 Option). This is required because we automatically implement all operators on Option, but in rare cases the operator’s behaviour isn’t well captured by returning false for None (e.g. `isnull).

Implementors