pub struct Condition {
pub expression: ConditionExpression,
pub operator: Operator,
pub value: Value,
/* private fields */
}Expand description
Represents a single condition in a rule
Fields§
§expression: ConditionExpressionThe expression to evaluate (field or function call)
operator: OperatorThe comparison operator to use
value: ValueThe value to compare against
Implementations§
Source§impl Condition
impl Condition
Sourcepub fn new(field: String, operator: Operator, value: Value) -> Self
pub fn new(field: String, operator: Operator, value: Value) -> Self
Create a new condition with a field reference
Sourcepub fn with_function(
function_name: String,
args: Vec<String>,
operator: Operator,
value: Value,
) -> Self
pub fn with_function( function_name: String, args: Vec<String>, operator: Operator, value: Value, ) -> Self
Create a new condition with a function call
Sourcepub fn with_test(function_name: String, args: Vec<String>) -> Self
pub fn with_test(function_name: String, args: Vec<String>) -> Self
Create a new Test CE condition The function must return a boolean value
Sourcepub fn with_multifield_collect(field: String, variable: String) -> Self
pub fn with_multifield_collect(field: String, variable: String) -> Self
Create multi-field collect condition Example: Order.items $?all_items
Sourcepub fn with_multifield_count(
field: String,
operator: Operator,
value: Value,
) -> Self
pub fn with_multifield_count( field: String, operator: Operator, value: Value, ) -> Self
Create multi-field count condition Example: Order.items count > 0
Sourcepub fn with_multifield_first(field: String, variable: Option<String>) -> Self
pub fn with_multifield_first(field: String, variable: Option<String>) -> Self
Create multi-field first condition Example: Queue.tasks first $first_task
Sourcepub fn with_multifield_last(field: String, variable: Option<String>) -> Self
pub fn with_multifield_last(field: String, variable: Option<String>) -> Self
Create multi-field last condition Example: Queue.tasks last $last_task
Sourcepub fn with_multifield_empty(field: String) -> Self
pub fn with_multifield_empty(field: String) -> Self
Create multi-field empty condition Example: ShoppingCart.items empty
Sourcepub fn with_multifield_not_empty(field: String) -> Self
pub fn with_multifield_not_empty(field: String) -> Self
Create multi-field not_empty condition Example: ShoppingCart.items not_empty
Sourcepub fn evaluate(&self, facts: &HashMap<String, Value>) -> bool
pub fn evaluate(&self, facts: &HashMap<String, Value>) -> bool
Evaluate this condition against the given facts
Sourcepub fn evaluate_with_engine(
&self,
facts: &HashMap<String, Value>,
function_registry: &HashMap<String, Arc<dyn Fn(Vec<Value>, &HashMap<String, Value>) -> Result<Value> + Send + Sync>>,
) -> bool
pub fn evaluate_with_engine( &self, facts: &HashMap<String, Value>, function_registry: &HashMap<String, Arc<dyn Fn(Vec<Value>, &HashMap<String, Value>) -> Result<Value> + Send + Sync>>, ) -> bool
Evaluate condition with access to engine’s function registry This is needed for function call evaluation
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Condition
impl RefUnwindSafe for Condition
impl Send for Condition
impl Sync for Condition
impl Unpin for Condition
impl UnwindSafe for Condition
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more