Skip to main content

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 the `async`
11//!   feature).
12//! - Flexible: sync, async, and priority-based listeners.
13//! - Simple API.
14//!
15//! ## Quick Start
16//!
17//! ```rust
18//! use mod_events::prelude::*;
19//!
20//! // Define your event
21//! #[derive(Debug, Clone)]
22//! struct UserRegistered {
23//!     user_id: u64,
24//!     email: String,
25//! }
26//!
27//! impl Event for UserRegistered {
28//!     fn as_any(&self) -> &dyn std::any::Any {
29//!         self
30//!     }
31//! }
32//!
33//! // Create dispatcher and subscribe
34//! let dispatcher = EventDispatcher::new();
35//! dispatcher.on(|event: &UserRegistered| {
36//!     println!("Welcome {}!", event.email);
37//! });
38//!
39//! // Dispatch events
40//! dispatcher.emit(UserRegistered {
41//!     user_id: 123,
42//!     email: "alice@example.com".to_string(),
43//! });
44//! ```
45
46#![deny(warnings)]
47#![deny(missing_docs)]
48#![deny(unsafe_op_in_unsafe_fn)]
49#![deny(unused_must_use)]
50#![deny(unused_results)]
51#![deny(clippy::unwrap_used)]
52#![deny(clippy::expect_used)]
53#![deny(clippy::todo)]
54#![deny(clippy::unimplemented)]
55#![deny(clippy::print_stdout)]
56#![deny(clippy::print_stderr)]
57#![deny(clippy::dbg_macro)]
58#![deny(clippy::unreachable)]
59#![deny(clippy::undocumented_unsafe_blocks)]
60#![deny(clippy::missing_safety_doc)]
61
62mod core;
63mod dispatcher;
64mod error;
65mod listener;
66mod metrics;
67mod middleware;
68mod priority;
69mod result;
70
71#[cfg(feature = "async")]
72mod async_support;
73
74pub use core::*;
75pub use dispatcher::*;
76pub use error::*;
77pub use listener::*;
78pub use metrics::*;
79pub use middleware::*;
80pub use priority::*;
81pub use result::*;
82
83#[cfg(feature = "async")]
84pub use async_support::*;
85
86/// Convenience re-exports
87pub mod prelude {
88    pub use crate::{Event, EventDispatcher, ListenerError, Priority};
89
90    #[cfg(feature = "async")]
91    pub use crate::AsyncEventListener;
92}