Trait Operator

Source
pub trait Operator<T> {
    // Required method
    fn apply(&self, value: &T) -> bool;

    // Provided methods
    fn empty_collection(&self) -> bool { ... }
    fn null_option(&self) -> bool { ... }
}
Available on crate feature filter only.
Expand description

Take a single 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<T> 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 ops module. Examples are exact, in, contains and so forth.

Required Methods§

Source

fn apply(&self, value: &T) -> bool

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

Provided Methods§

Source

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.

Source

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 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 for. isnull).

Implementors§

Source§

impl<T> Operator<T> for ContainsImpl
where T: Display,

Source§

impl<T> Operator<T> for EndsWithImpl
where T: Display,

Source§

impl<T> Operator<T> for ExactImpl<T>
where T: Eq,

Source§

impl<T> Operator<T> for GreaterEqImpl<T>
where T: Ord,

Source§

impl<T> Operator<T> for GreaterImpl<T>
where T: Ord,

Source§

impl<T> Operator<T> for IContainsImpl
where T: Display,

Source§

impl<T> Operator<T> for IExactImpl
where T: Display,

Source§

impl<T> Operator<T> for InImpl<T>
where T: Eq + FromStr,

Source§

impl<T> Operator<T> for IsNullImpl

Source§

impl<T> Operator<T> for LessEqImpl<T>
where T: Ord,

Source§

impl<T> Operator<T> for LessImpl<T>
where T: Ord,

Source§

impl<T> Operator<T> for StartsWithImpl
where T: Display,