use std::fmt::Debug;
use std::hash::Hash;
pub trait ActionType: Clone + PartialEq + Eq + std::hash::Hash + Send + Sync + 'static {
fn name(&self) -> &str;
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum DefaultAction {
Default,
Next,
Error,
Custom(String),
}
impl DefaultAction {
pub fn new(name: impl Into<String>) -> Self {
Self::Custom(name.into())
}
}
impl Default for DefaultAction {
fn default() -> Self {
Self::Default
}
}
impl ActionType for DefaultAction {
fn name(&self) -> &str {
match self {
Self::Default => "default",
Self::Next => "next",
Self::Error => "error",
Self::Custom(name) => name,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_action_name() {
assert_eq!(DefaultAction::Default.name(), "default");
assert_eq!(DefaultAction::Next.name(), "next");
assert_eq!(DefaultAction::Error.name(), "error");
assert_eq!(DefaultAction::Custom("custom".into()).name(), "custom");
}
#[test]
fn test_default_action_creation() {
let action = DefaultAction::new("test-action");
assert_eq!(action, DefaultAction::Custom("test-action".into()));
assert_eq!(action.name(), "test-action");
}
}