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.,Stringfor tags,u32for 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§
Sourcefn get_universal(&mut self) -> Result<R, E>
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.
Sourcefn eval_set(&mut self, set: &T) -> Result<R, E>
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.
Sourcefn eval_union<'a, I>(&mut self, values: I) -> Result<R, E>
fn eval_union<'a, I>(&mut self, values: I) -> Result<R, E>
Sourcefn eval_intersection<'a, I>(&mut self, values: I) -> Result<R, E>
fn eval_intersection<'a, I>(&mut self, values: I) -> Result<R, E>
Sourcefn eval_difference(&mut self, include: &R, exclude: &R) -> Result<R, E>
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.
!Abecomeseval_difference(Universal, A)A & !Bbecomeseval_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.