rust_rule_engine/rete/
action_result.rs

1//! Action Results
2//!
3//! This module defines the results that actions can return to communicate
4//! with the engine (e.g., retract facts, activate agenda groups, etc.)
5
6use super::FactHandle;
7
8/// Result of executing a rule action
9/// Actions can return side effects that need to be handled by the engine
10#[derive(Debug, Clone)]
11pub enum ActionResult {
12    /// Retract a fact by handle
13    Retract(FactHandle),
14    
15    /// Retract a fact by fact type (first matching fact)
16    RetractByType(String),
17    
18    /// Update/modify a fact (trigger re-evaluation)
19    Update(FactHandle),
20    
21    /// Activate an agenda group
22    ActivateAgendaGroup(String),
23    
24    /// Insert a new fact
25    InsertFact {
26        fact_type: String,
27        data: super::TypedFacts,
28    },
29    
30    /// Insert a logical fact (with justification)
31    InsertLogicalFact {
32        fact_type: String,
33        data: super::TypedFacts,
34        rule_name: String,
35        premises: Vec<FactHandle>,
36    },
37    
38    /// Call a custom function (requires function registry)
39    CallFunction {
40        function_name: String,
41        args: Vec<String>,
42    },
43    
44    /// Schedule a rule to fire later
45    ScheduleRule {
46        rule_name: String,
47        delay_ms: u64,
48    },
49    
50    /// No side effect, just modify facts
51    None,
52}
53
54/// Container for multiple action results
55#[derive(Debug, Clone, Default)]
56pub struct ActionResults {
57    pub results: Vec<ActionResult>,
58}
59
60impl ActionResults {
61    pub fn new() -> Self {
62        Self {
63            results: Vec::new(),
64        }
65    }
66    
67    pub fn add(&mut self, result: ActionResult) {
68        self.results.push(result);
69    }
70    
71    pub fn is_empty(&self) -> bool {
72        self.results.is_empty()
73    }
74    
75    pub fn len(&self) -> usize {
76        self.results.len()
77    }
78}