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 { rule_name: String, delay_ms: u64 },
46
47    /// No side effect, just modify facts
48    None,
49}
50
51/// Container for multiple action results
52#[derive(Debug, Clone, Default)]
53pub struct ActionResults {
54    pub results: Vec<ActionResult>,
55}
56
57impl ActionResults {
58    pub fn new() -> Self {
59        Self {
60            results: Vec::new(),
61        }
62    }
63
64    pub fn add(&mut self, result: ActionResult) {
65        self.results.push(result);
66    }
67
68    pub fn is_empty(&self) -> bool {
69        self.results.is_empty()
70    }
71
72    pub fn len(&self) -> usize {
73        self.results.len()
74    }
75}