async_events_emitter/
event.rs

1use std::any::{Any, TypeId};
2use async_trait::async_trait;
3
4
5pub trait Event: Any + Send + Sync {
6    fn type_id(&self) -> TypeId {
7        TypeId::of::<Self>()
8    }
9}
10
11#[derive(Debug)]
12pub enum EventError {
13    // Define various kinds of errors that might occur
14    HandlerError(String),
15}
16
17// Define an async trait for handlers
18#[async_trait]
19pub trait EventHandler<E: Event + Send + Sync + 'static>: Send + Sync {
20    async fn handle_event(&mut self, event: &E);
21}