#![deny(missing_docs)]
#[cfg(not(any(feature = "async", feature = "sync")))]
compile_error!("Either `async` or `sync` feature must be enabled");
#[cfg(all(feature = "async", feature = "sync"))]
compile_error!("The `async` and `sync` features cannot be enabled simultaneously");
pub mod error;
pub mod event;
#[cfg(feature = "async")]
mod impl_async;
#[cfg(feature = "sync")]
mod impl_sync;
#[cfg(test)]
mod tests;
#[cfg(feature = "async")]
pub use async_trait::async_trait;
#[cfg(feature = "async")]
pub use impl_async::Handle;
#[cfg(feature = "sync")]
pub use impl_sync::Handle;
#[cfg(feature = "sync")]
use std::sync::Mutex;
#[cfg(feature = "async")]
use tokio::sync::Mutex;
use std::{collections::HashMap, sync::Arc};
use uuid::Uuid;
pub type Handler<T> = Box<dyn Handle<T>>;
pub type HandlerMap<T> = Arc<Mutex<HashMap<HandlerId, Handler<T>>>>;
pub type EventHandlerMap<T> = Arc<Mutex<HashMap<String, HandlerMap<T>>>>;
#[derive(Default)]
pub struct EventBus<T> {
event_handler_map: EventHandlerMap<T>,
}
impl<T> EventBus<T> {
pub fn new() -> Self {
Self {
event_handler_map: Default::default(),
}
}
}
#[derive(Eq, Hash, PartialEq, Clone, Debug, Default)]
pub struct HandlerId {
id: Uuid,
}
impl HandlerId {
pub fn new() -> Self {
Self { id: Uuid::new_v4() }
}
}