pub struct RuleEngine { /* private fields */ }Expand description
The main rule execution engine.
Holds a compiled ruleset and provides methods to execute rules against data.
§Performance
The engine pre-sorts rules by priority during construction and performs minimal allocations during execution.
Implementations§
Source§impl RuleEngine
impl RuleEngine
Sourcepub fn new(ruleset: RuleSet) -> Self
pub fn new(ruleset: RuleSet) -> Self
Creates a new rule engine from a ruleset.
§Warning Detection
This constructor checks for duplicate priorities within categories and logs warnings if found (order of execution may be non-deterministic).
§Examples
use fast_decision::{RuleEngine, RuleSet};
let ruleset: RuleSet = serde_json::from_str(rules_json).unwrap();
let engine = RuleEngine::new(ruleset);Sourcepub fn execute<'a>(
&'a self,
data: &Value,
categories_to_run: &[&str],
) -> Vec<&'a Rule>
pub fn execute<'a>( &'a self, data: &Value, categories_to_run: &[&str], ) -> Vec<&'a Rule>
Executes rules from specified categories against the provided data.
§Arguments
data- JSON data to evaluate rules againstcategories_to_run- List of category names to execute
§Returns
A vector of references to Rule objects that matched the data, in priority order.
§Behavior
- Rules are evaluated in priority order (lower priority value = higher precedence)
- If a category has
stop_on_first: true, execution stops after the first match - Non-existent categories are silently skipped
- Results accumulate across all requested categories
§Performance
- O(n) where n is total number of rules in requested categories
- Pre-allocates result vector with exact capacity
- Minimal allocations during execution
§Examples
let data = json!({"user": {"tier": "Gold"}});
let results = engine.execute(&data, &["Pricing", "Fraud"]);
for rule in results {
println!("Matched rule: {} - {}", rule.id, rule.action);
}Auto Trait Implementations§
impl Freeze for RuleEngine
impl RefUnwindSafe for RuleEngine
impl Send for RuleEngine
impl Sync for RuleEngine
impl Unpin for RuleEngine
impl UnwindSafe for RuleEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more