pub struct IncrementalEngine { /* private fields */ }Expand description
Incremental Propagation Engine Only re-evaluates rules affected by changed facts
Implementations§
Source§impl IncrementalEngine
impl IncrementalEngine
Sourcepub fn add_rule(&mut self, rule: TypedReteUlRule, depends_on: Vec<String>)
pub fn add_rule(&mut self, rule: TypedReteUlRule, depends_on: Vec<String>)
Add rule and register its dependencies
Sourcepub fn insert(&mut self, fact_type: String, data: TypedFacts) -> FactHandle
pub fn insert(&mut self, fact_type: String, data: TypedFacts) -> FactHandle
Insert fact into working memory
Sourcepub fn update(&mut self, handle: FactHandle, data: TypedFacts) -> Result<()>
pub fn update(&mut self, handle: FactHandle, data: TypedFacts) -> Result<()>
Update fact in working memory
Sourcepub fn retract(&mut self, handle: FactHandle) -> Result<()>
pub fn retract(&mut self, handle: FactHandle) -> Result<()>
Retract fact from working memory
Sourcepub fn insert_explicit(
&mut self,
fact_type: String,
data: TypedFacts,
) -> FactHandle
pub fn insert_explicit( &mut self, fact_type: String, data: TypedFacts, ) -> FactHandle
Insert a fact with explicit assertion (user provided) This fact will NOT be auto-retracted by TMS
Sourcepub fn insert_logical(
&mut self,
fact_type: String,
data: TypedFacts,
source_rule: String,
premise_handles: Vec<FactHandle>,
) -> FactHandle
pub fn insert_logical( &mut self, fact_type: String, data: TypedFacts, source_rule: String, premise_handles: Vec<FactHandle>, ) -> FactHandle
Insert a fact with logical assertion (derived by a rule) This fact WILL be auto-retracted if its premises become invalid
§Arguments
fact_type- Type of the fact (e.g., “Customer”)data- The fact datasource_rule- Name of the rule deriving this factpremise_handles- Handles of facts matched in the rule’s WHEN clause
Sourcepub fn resolve_premise_keys(&self, premise_keys: Vec<String>) -> Vec<FactHandle>
pub fn resolve_premise_keys(&self, premise_keys: Vec<String>) -> Vec<FactHandle>
Resolve premise keys (format: “Type.field=value” or “Type.field=”)
to a Vec
Sourcepub fn tms(&self) -> &TruthMaintenanceSystem
pub fn tms(&self) -> &TruthMaintenanceSystem
Get TMS reference
Sourcepub fn tms_mut(&mut self) -> &mut TruthMaintenanceSystem
pub fn tms_mut(&mut self) -> &mut TruthMaintenanceSystem
Get mutable TMS reference
Sourcepub fn working_memory(&self) -> &WorkingMemory
pub fn working_memory(&self) -> &WorkingMemory
Get working memory
Sourcepub fn working_memory_mut(&mut self) -> &mut WorkingMemory
pub fn working_memory_mut(&mut self) -> &mut WorkingMemory
Get mutable working memory
Sourcepub fn agenda(&self) -> &AdvancedAgenda
pub fn agenda(&self) -> &AdvancedAgenda
Get agenda
Sourcepub fn agenda_mut(&mut self) -> &mut AdvancedAgenda
pub fn agenda_mut(&mut self) -> &mut AdvancedAgenda
Get mutable agenda
Sourcepub fn set_conflict_resolution_strategy(
&mut self,
strategy: ConflictResolutionStrategy,
)
pub fn set_conflict_resolution_strategy( &mut self, strategy: ConflictResolutionStrategy, )
Set conflict resolution strategy
Controls how conflicting rules in the agenda are ordered. Available strategies: Salience (default), LEX, MEA, Depth, Breadth, Simplicity, Complexity, Random
Sourcepub fn conflict_resolution_strategy(&self) -> ConflictResolutionStrategy
pub fn conflict_resolution_strategy(&self) -> ConflictResolutionStrategy
Get current conflict resolution strategy
Sourcepub fn stats(&self) -> IncrementalEngineStats
pub fn stats(&self) -> IncrementalEngineStats
Get statistics
Sourcepub fn templates(&self) -> &TemplateRegistry
pub fn templates(&self) -> &TemplateRegistry
Get template registry
Sourcepub fn templates_mut(&mut self) -> &mut TemplateRegistry
pub fn templates_mut(&mut self) -> &mut TemplateRegistry
Get mutable template registry
Sourcepub fn register_function<F>(&mut self, name: &str, func: F)
pub fn register_function<F>(&mut self, name: &str, func: F)
Register a custom function for Test CE support
§Example
use rust_rule_engine::rete::{IncrementalEngine, FactValue};
let mut engine = IncrementalEngine::new();
engine.register_function(
"is_valid_email",
|args, _facts| {
if let Some(FactValue::String(email)) = args.first() {
Ok(FactValue::Boolean(email.contains('@')))
} else {
Ok(FactValue::Boolean(false))
}
}
);Sourcepub fn get_function(&self, name: &str) -> Option<&ReteCustomFunction>
pub fn get_function(&self, name: &str) -> Option<&ReteCustomFunction>
Get a custom function by name (for Test CE evaluation)
Sourcepub fn globals(&self) -> &GlobalsRegistry
pub fn globals(&self) -> &GlobalsRegistry
Get global variables registry
Sourcepub fn globals_mut(&mut self) -> &mut GlobalsRegistry
pub fn globals_mut(&mut self) -> &mut GlobalsRegistry
Get mutable global variables registry
Sourcepub fn deffacts(&self) -> &DeffactsRegistry
pub fn deffacts(&self) -> &DeffactsRegistry
Get deffacts registry
Sourcepub fn deffacts_mut(&mut self) -> &mut DeffactsRegistry
pub fn deffacts_mut(&mut self) -> &mut DeffactsRegistry
Get mutable deffacts registry
Sourcepub fn load_deffacts(&mut self) -> Vec<FactHandle>
pub fn load_deffacts(&mut self) -> Vec<FactHandle>
Load all registered deffacts into working memory Returns handles of all inserted facts
Sourcepub fn load_deffacts_by_name(&mut self, name: &str) -> Result<Vec<FactHandle>>
pub fn load_deffacts_by_name(&mut self, name: &str) -> Result<Vec<FactHandle>>
Load a specific deffacts set by name Returns handles of inserted facts or error if deffacts not found
Sourcepub fn reset_with_deffacts(&mut self) -> Vec<FactHandle>
pub fn reset_with_deffacts(&mut self) -> Vec<FactHandle>
Reset engine and reload all deffacts (similar to CLIPS reset) Clears working memory and agenda, then loads all deffacts
Sourcepub fn insert_with_template(
&mut self,
template_name: &str,
data: TypedFacts,
) -> Result<FactHandle>
pub fn insert_with_template( &mut self, template_name: &str, data: TypedFacts, ) -> Result<FactHandle>
Insert a typed fact with template validation
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for IncrementalEngine
impl !RefUnwindSafe for IncrementalEngine
impl Send for IncrementalEngine
impl Sync for IncrementalEngine
impl Unpin for IncrementalEngine
impl !UnwindSafe for IncrementalEngine
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more