Expand description
§fast-decision
A high-performance rule engine.
This crate provides a rule execution engine optimized for speed with zero-cost abstractions.
§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
- Condition 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:
- Rule execution engine (
RuleEngine) - Type definitions and data structures (
RuleSet,Category,Rule,Predicate) - Python bindings via PyO3 (
FastDecisionclass)
§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.
- Rule
Engine - The main rule execution engine.
- RuleSet
- Top-level container for all rule categories.