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