Evaluator

Trait Evaluator 

Source
pub trait Evaluator<T, R, E> {
    // Required methods
    fn get_universal(&mut self) -> Result<R, E>;
    fn get_empty(&mut self) -> Result<R, E>;
    fn eval_set(&mut self, set: &T) -> Result<R, E>;
    fn eval_union<'a, I>(&mut self, values: I) -> Result<R, E>
       where R: 'a,
             I: IntoIterator<Item = &'a R>,
             I::IntoIter: ExactSizeIterator;
    fn eval_intersection<'a, I>(&mut self, values: I) -> Result<R, E>
       where R: 'a,
             I: IntoIterator<Item = &'a R>,
             I::IntoIter: ExactSizeIterator;
    fn eval_difference(&mut self, include: &R, exclude: &R) -> Result<R, E>;
}
Expand description

Defines how to resolve abstract logic into concrete results.

To run an Expression, you must implement this trait. It acts as the bridge between the boolean logic graph and your specific domain (e.g., SQL generation, bitmask operations, search engine query execution).

§Type Parameters

  • T: The Term type used in the expression (e.g., String for tags, u32 for IDs).
  • R: The Result type produced by the evaluation (e.g., Vec<i32>, RoaringBitmap, SqlFragment).
  • E: The Error type that can occur during evaluation.

§Optimization Note

This trait uses eval_difference instead of a direct not method. This allows implementations to avoid calculating “Everything except X” (which is often expensive or infinite) and instead implicitly calculate A AND NOT B.

Required Methods§

Source

fn get_universal(&mut self) -> Result<R, E>

Returns the Universal Set (The set of all things).

This is used when the expression resolves to a pure negation (e.g., !A). To resolve !A, the library calculates Universal - A.

If your domain does not support a “Universal” set (e.g., an infinite number line), you can return an error here, but be aware that top-level negations will fail.

Source

fn get_empty(&mut self) -> Result<R, E>

Returns the Empty Set (The set of nothing).

Source

fn eval_set(&mut self, set: &T) -> Result<R, E>

Resolves a single leaf node value into a result.

§Example

If T is a User ID, this might look up that user in a database and return a Result containing that user’s permissions.

Source

fn eval_union<'a, I>(&mut self, values: I) -> Result<R, E>
where R: 'a, I: IntoIterator<Item = &'a R>, I::IntoIter: ExactSizeIterator,

merges multiple results via a Union (OR) operation.

§Arguments
  • values - An iterator of results previously computed by eval_set, eval_intersection, etc.
§Expected Behavior

Return a result containing items present in at least one of the input values.

Source

fn eval_intersection<'a, I>(&mut self, values: I) -> Result<R, E>
where R: 'a, I: IntoIterator<Item = &'a R>, I::IntoIter: ExactSizeIterator,

Filters multiple results via an Intersection (AND) operation.

§Arguments
  • values - An iterator of results previously computed by eval_set, eval_intersection, etc.
§Expected Behavior

Return a result containing only items present in all of the input values.

Source

fn eval_difference(&mut self, include: &R, exclude: &R) -> Result<R, E>

Calculates the difference between two results (Include AND NOT Exclude).

This is used to handle negation. The expression engine transforms negations into difference operations where possible to avoid materializing the Universal set.

  • !A becomes eval_difference(Universal, A)
  • A & !B becomes eval_difference(A, B)
§Arguments
  • include - The base set of items.
  • exclude - The set of items to remove from the base set.

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.

Implementors§

Source§

impl<K, S> Evaluator<K, S, ()> for BitwiseEval<K, S>
where K: Hash + Eq, for<'a> S: Default + Clone + BitOrAssign<&'a S> + BitAndAssign<&'a S>, for<'a> &'a S: Sub<Output = S>,

Source§

impl<T: Hash + Eq> Evaluator<T, bool, ()> for BoolEval<T>