floxide_core/
action.rs

1use std::fmt::Debug;
2use std::hash::Hash;
3
4/// Trait for action types that can be used for node transitions
5pub trait ActionType: Clone + PartialEq + Eq + std::hash::Hash + Send + Sync + 'static {
6    /// Get the name of this action
7    fn name(&self) -> &str;
8}
9
10/// Default action type for simple workflows
11#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12pub enum DefaultAction {
13    /// Default action (used for fallback routing)
14    Default,
15    /// Next node in sequence
16    Next,
17    /// Error handler
18    Error,
19    /// Custom named action
20    Custom(String),
21}
22
23impl DefaultAction {
24    /// Create a new custom action with the given name
25    pub fn new(name: impl Into<String>) -> Self {
26        Self::Custom(name.into())
27    }
28}
29
30impl Default for DefaultAction {
31    fn default() -> Self {
32        Self::Default
33    }
34}
35
36impl ActionType for DefaultAction {
37    fn name(&self) -> &str {
38        match self {
39            Self::Default => "default",
40            Self::Next => "next",
41            Self::Error => "error",
42            Self::Custom(name) => name,
43        }
44    }
45}
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_default_action_name() {
53        assert_eq!(DefaultAction::Default.name(), "default");
54        assert_eq!(DefaultAction::Next.name(), "next");
55        assert_eq!(DefaultAction::Error.name(), "error");
56        assert_eq!(DefaultAction::Custom("custom".into()).name(), "custom");
57    }
58
59    #[test]
60    fn test_default_action_creation() {
61        let action = DefaultAction::new("test-action");
62        assert_eq!(action, DefaultAction::Custom("test-action".into()));
63        assert_eq!(action.name(), "test-action");
64    }
65}