epicenter/lib.rs
1#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo)]
2
3//! A simple sync/async event dispatcher.
4//!
5//! # Usage
6//!
7//! ```rust
8//! use epicenter::{Event, AsyncDispatcher};
9//!
10//! # #[derive(Debug, Clone)]
11//! struct OrderShipped {
12//! order_id: u64
13//! }
14//! impl Event for OrderShipped {}
15//!
16//! # #[tokio::main]
17//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
18//! let mut dispatcher = AsyncDispatcher::new();
19//!
20//! dispatcher.listen(|event: OrderShipped| async move {
21//! assert_eq!(event.order_id, 123);
22//! }).await;
23//!
24//! dispatcher.dispatch(&OrderShipped { order_id: 123 }).await?;
25//! # Ok(())
26//! # }
27//! ```
28
29pub mod dispatchers;
30
31#[cfg(feature = "async")]
32pub use dispatchers::r#async::Dispatcher as AsyncDispatcher;
33pub use dispatchers::sync::Dispatcher as SyncDispatcher;
34
35pub trait Event {}