Skip to main content

RulesEngine

Struct RulesEngine 

Source
pub struct RulesEngine { /* private fields */ }
Expand description

The rules engine evaluates rules against state changes.

Implementations§

Source§

impl RulesEngine

Source

pub fn new() -> Self

Create a new empty rules engine

Source

pub fn add_rule(&mut self, rule: Rule) -> Result<()>

Add or update a rule

Source

pub fn remove_rule(&mut self, id: &str) -> Result<()>

Remove a rule by ID

Source

pub fn get_rule(&self, id: &str) -> Option<&Rule>

Get a rule by ID

Source

pub fn rules(&self) -> impl Iterator<Item = &Rule>

Get all rules

Source

pub fn len(&self) -> usize

Number of rules

Source

pub fn is_empty(&self) -> bool

Check if empty

Source

pub fn set_enabled(&mut self, id: &str, enabled: bool) -> Result<()>

Enable or disable a rule

Source

pub fn evaluate<F>( &mut self, address: &str, value: &Value, signal_type: SignalType, origin: Option<&str>, state_lookup: F, ) -> Vec<PendingAction>
where F: Fn(&str) -> Option<Value>,

Evaluate rules triggered by a state change.

address: the address that changed value: the new value signal_type: Param or Event origin: if set, skip rules that originated from this source (loop prevention) state_lookup: function to look up current param values (for conditions)

Returns actions that should be executed by the router.

Source

pub fn evaluate_interval<F>( &mut self, rule_id: &str, state_lookup: F, ) -> Vec<PendingAction>
where F: Fn(&str) -> Option<Value>,

Evaluate an interval rule by ID.

Unlike evaluate(), this doesn’t match on address/signal_type — it fires the rule directly (checking enabled, cooldown, and conditions). Returns actions that should be executed by the router.

Source

pub fn interval_rules(&self) -> Vec<(String, u64)>

Get rule IDs that have interval triggers (for the router to schedule)

Trait Implementations§

Source§

impl Default for RulesEngine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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.