Crate fast_decision

Crate fast_decision 

Source
Expand description

§fast-decision

A high-performance rule engine with MongoDB-style query syntax.

This crate provides a rule execution engine optimized for speed with zero-cost abstractions. Rules are defined using a MongoDB-style syntax and can be executed against JSON data.

§Features

  • Priority-based execution: Rules are sorted by priority (lower values = higher priority)
  • Stop-on-first: Per-category flag to stop execution after the first matching rule
  • MongoDB-style operators: $eq, $ne, $gt, $lt, $gte, $lte, $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 execution (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": {"$eq": "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.execute(&data, &["Pricing"]);
println!("Triggered rules: {:?}", results);

Structs§

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

Enums§

Operator
MongoDB-style comparison operators.
Predicate
Abstract Syntax Tree (AST) node for condition evaluation.