mod_events/lib.rs
1//! # Mod Events
2//!
3//! A high-performance, zero-overhead event dispatcher library for Rust.
4//!
5//! ## Features
6//!
7//! - **Zero-cost abstractions**: No runtime overhead for event dispatch
8//! - **Type-safe**: Compile-time guarantees for event handling
9//! - **Thread-safe**: Built for concurrent applications
10//! - **Async support**: Full async/await compatibility (with "async" feature)
11//! - **Flexible**: Support for sync, async, and priority-based listeners
12//! - **Easy to use**: Simple API and intuitive methods
13//!
14//! ## Quick Start
15//!
16//! ```rust
17//! use mod_events::prelude::*;
18//!
19//! // Define your event
20//! #[derive(Debug, Clone)]
21//! struct UserRegistered {
22//! user_id: u64,
23//! email: String,
24//! }
25//!
26//! impl Event for UserRegistered {
27//! fn as_any(&self) -> &dyn std::any::Any {
28//! self
29//! }
30//! }
31//!
32//! // Create dispatcher and subscribe
33//! let dispatcher = EventDispatcher::new();
34//! dispatcher.on(|event: &UserRegistered| {
35//! println!("Welcome {}!", event.email);
36//! });
37//!
38//! // Dispatch events
39//! dispatcher.emit(UserRegistered {
40//! user_id: 123,
41//! email: "alice@example.com".to_string(),
42//! });
43//! ```
44mod core;
45mod dispatcher;
46mod listener;
47mod metrics;
48mod middleware;
49mod priority;
50mod result;
51
52#[cfg(feature = "async")]
53mod async_support;
54
55pub use core::*;
56pub use dispatcher::*;
57pub use listener::*;
58pub use metrics::*;
59pub use middleware::*;
60pub use priority::*;
61pub use result::*;
62
63#[cfg(feature = "async")]
64pub use async_support::*;
65
66/// Convenience re-exports
67pub mod prelude {
68 pub use crate::{Event, EventDispatcher, Priority};
69
70 #[cfg(feature = "async")]
71 pub use crate::AsyncEventListener;
72}