Crate fast_decision

Crate fast_decision 

Source
Expand description

§fast-decision

A high-performance rule engine.

This crate provides a rule evaluation engine optimized for speed with zero-cost abstractions.

§Features

  • Priority-based evaluation: Rules are sorted by priority (lower values = higher priority)
  • Stop-on-first: Per-category flag to stop evaluation after the first matching rule
  • Condition operators: $equals, $not-equals, $greater-than, $less-than, $greater-than-or-equals, $less-than-or-equals, $in, $not-in, $contains, $starts-with, $ends-with, $regex, $and, $or
  • Zero-cost abstractions: Optimized Rust core with minimal allocations in hot paths
  • Python bindings: Native performance accessible from Python via PyO3

§Architecture

The engine consists of three main components:

§Performance Characteristics

  • O(n) rule evaluation where n is the number of rules in requested categories
  • O(d) nested field access where d is the depth of field path
  • Minimal allocations during evaluation (results only)
  • Optimized comparison operations with inline hints

§Example (Rust)

use fast_decision::{RuleEngine, RuleSet};
use serde_json::json;

let rules_json = r#"
{
  "categories": {
    "Pricing": {
      "stop_on_first": true,
      "rules": [{
        "id": "Premium",
        "priority": 1,
        "conditions": {"user.tier": {"$equals": "Gold"}},
        "action": "apply_discount"
      }]
    }
  }
}
"#;

let ruleset: RuleSet = serde_json::from_str(rules_json).unwrap();
let engine = RuleEngine::new(ruleset);

let data = json!({"user": {"tier": "Gold"}});
let results = engine.evaluate_rules(&data, &["Pricing"]);
println!("Triggered rules: {:?}", results);

Structs§

Category
A category containing multiple rules with evaluation settings.
Comparison
A single field comparison operation.
Rule
An individual rule with conditions and action.
RuleEngine
The main rule evaluation engine.
RuleSet
Top-level container for all rule categories.

Enums§

Operator
Comparison operators.
Predicate
Abstract Syntax Tree (AST) node for condition evaluation.