Skip to main content

Crate ooroo

Crate ooroo 

Source
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.
ContextBuilder
Builder for constructing an IndexedContext. Obtained from RuleSet::context_builder().
EvaluationReport
Detailed evaluation report returned by RuleSet::evaluate_detailed().
FieldExpr
Intermediate builder for field comparison expressions. Created by field(); requires a comparison method to produce a valid Expr.
FieldRegistry
Maps field paths (e.g. "user.profile.age") to flat integer indices.
IndexedContext
A pre-indexed context for fast evaluation. Values are stored in a flat Vec with indices matching the compiled ruleset’s field registry.
ParseError
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.
RuleSetBuilder
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 RuleSet against a context.

Enums§

Bound
A bound used in range and membership expressions.
CompareOp
Comparison operators supported in rule expressions.
CompileError
Errors produced during ruleset compilation.
Expr
User-facing expression AST. Field paths and rule names are strings. Transformed into a compiled representation during compilation.
OorooError
Unified error type covering parsing, compilation, and I/O.
Value
Supported value types for rule evaluation.

Functions§

at_least
Create an Expr::AtLeast that is true when at least n of the given expressions evaluate to true.
bound_field
Create a Bound that references a context field by path.
field
Create a FieldExpr for building field comparison expressions.
rule_ref
Create an Expr that references another rule by name.