Expand description
A Rust port of boolrule.
This library evaluates boolean expressions.
§Usage
To use this library, you need to create a CoolRule
instance by parsing a boolean expression string.
The library supports evaluating boolean expressions containing various operations such as and
, or
, not
, comparisons, and set membership checks.
Expressions can be evaluated with or without a context, where the context provides values for variables used in the expression.
§Examples
Creating and testing an expression without context:
let expr = coolrule::new("1 > 2 and 3 <= 5").unwrap();
let result = expr.test().unwrap(); // false
Creating and testing an expression with context:
use coolrule::{Value};
use std::collections::HashMap;
let expr = coolrule::new("x == 5").unwrap();
let mut context = HashMap::new();
context.insert(vec!["x"], Value::Number(5.0));
let result = expr.test_with_context(&context).unwrap(); // true
Structs§
- Cool
Rule - Represents a parsed and processed boolean expression.
Enums§
- Cool
Rule Error - Value
- Represents possible values that can be used in boolean expressions.
Functions§
- new
- Creates a new
CoolRule
instance by parsing the given boolean expression string.