RuleEngine

Struct RuleEngine 

Source
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

Source

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);
Source

pub fn execute<'a>( &'a self, data: &Value, categories_to_run: &[&str], ) -> Vec<&'a str>

Executes rules from specified categories against the provided data.

§Arguments
  • data - JSON data to evaluate rules against
  • categories_to_run - List of category names to execute
§Returns

A vector of rule IDs (as string slices) 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_id in results {
    println!("Matched rule: {}", rule_id);
}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Ungil for T
where T: Send,