use crate::{dispatched_event::DispatchedEvent, event_dispatcher::event_dispatcher};
use async_trait::async_trait;
pub trait Dispatchable: Send + Sync {
fn event() -> String
where
Self: Sized,
{
std::any::type_name::<Self>().to_string()
}
fn dispatch_event(self)
where
Self: Sized + 'static,
{
event_dispatcher().dispatch(self);
}
}
#[async_trait]
pub trait EventHandler: Send + Sync + 'static {
async fn handle(&self, event: &DispatchedEvent);
fn to_handler(self) -> Box<Self>
where
Self: Sized,
{
Box::new(self)
}
fn handler_id(&self) -> String {
std::any::type_name::<Self>().to_string()
}
}