Expand description
§Ooroo
A fast, compiled rule engine for Rust.
Ooroo is designed around a compile-once, evaluate-many architecture:
rulesets are compiled into an optimized, immutable execution structure that
can be shared across threads via Arc and evaluated concurrently with zero
synchronization overhead.
§Quick Start
use ooroo::{RuleSetBuilder, Context, field, rule_ref};
let ruleset = RuleSetBuilder::new()
.rule("eligible_age", |r| r.when(field("user.age").gte(18_i64)))
.rule("active_account", |r| r.when(field("user.status").eq("active")))
.rule("can_proceed", |r| {
r.when(rule_ref("eligible_age").and(rule_ref("active_account")))
})
.terminal("can_proceed", 0)
.compile()
.expect("failed to compile ruleset");
let ctx = Context::new()
.set("user.age", 25_i64)
.set("user.status", "active");
let result = ruleset.evaluate(&ctx);
assert!(result.is_some());
assert_eq!(result.unwrap().terminal(), "can_proceed");§Performance
For maximum throughput, use RuleSet::context_builder() to create an
IndexedContext and evaluate with RuleSet::evaluate_indexed(). This
eliminates all string lookups from the hot path.
let ctx = ruleset.context_builder()
.set("x", 10_i64)
.build();
let result = ruleset.evaluate_indexed(&ctx);Structs§
- Context
- Evaluation context mapping dot-separated field paths to
Values. - Context
Builder - Builder for constructing an
IndexedContext. Obtained fromRuleSet::context_builder(). - Evaluation
Report - Detailed evaluation report returned by
RuleSet::evaluate_detailed(). - Field
Expr - Intermediate builder for field comparison expressions.
Created by
field(); requires a comparison method to produce a validExpr. - Field
Registry - Maps field paths (e.g.
"user.profile.age") to flat integer indices. - Indexed
Context - A pre-indexed context for fast evaluation. Values are stored in a flat
Vecwith indices matching the compiled ruleset’s field registry. - Parse
Error - Errors produced when parsing DSL input.
- Rule
- A named rule with an optional boolean condition expression.
- RuleSet
- A compiled, immutable ruleset. Thread-safe and designed to live behind
Arc. - Rule
SetBuilder - Builder for constructing a
RuleSet. - Terminal
- Marks a rule as a terminal output of evaluation, with a priority that controls the order in which terminals are checked.
- Verdict
- The result of evaluating a
RuleSetagainst a context.
Enums§
- Bound
- A bound used in range and membership expressions.
- Compare
Op - Comparison operators supported in rule expressions.
- Compile
Error - Errors produced during ruleset compilation.
- Expr
- User-facing expression AST. Field paths and rule names are strings. Transformed into a compiled representation during compilation.
- Ooroo
Error - Unified error type covering parsing, compilation, and I/O.
- Value
- Supported value types for rule evaluation.
Functions§
- at_
least - Create an
Expr::AtLeastthat is true when at leastnof the given expressions evaluate to true. - bound_
field - Create a
Boundthat references a context field by path. - field
- Create a
FieldExprfor building field comparison expressions. - rule_
ref - Create an
Exprthat references another rule by name.