1use std::fmt::Debug;
2use std::hash::Hash;
3
4pub trait ActionType: Clone + PartialEq + Eq + std::hash::Hash + Send + Sync + 'static {
6 fn name(&self) -> &str;
8}
9
10#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12pub enum DefaultAction {
13 Default,
15 Next,
17 Error,
19 Custom(String),
21}
22
23impl DefaultAction {
24 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}