Expand description
§Mod Events
A high-performance, zero-overhead event dispatcher library for Rust.
§Features
- Zero-cost abstractions: no runtime overhead for event dispatch.
- Type-safe: compile-time guarantees for event handling.
- Thread-safe: built for concurrent applications.
- Async support: full
async/.awaitcompatibility (with theasyncfeature). - Flexible: sync, async, and priority-based listeners.
- Simple API.
§Quick Start
use mod_events::prelude::*;
// Define your event
#[derive(Debug, Clone)]
struct UserRegistered {
user_id: u64,
email: String,
}
impl Event for UserRegistered {
fn as_any(&self) -> &dyn std::any::Any {
self
}
}
// Create dispatcher and subscribe
let dispatcher = EventDispatcher::new();
dispatcher.on(|event: &UserRegistered| {
println!("Welcome {}!", event.email);
});
// Dispatch events
dispatcher.emit(UserRegistered {
user_id: 123,
email: "alice@example.com".to_string(),
});Modules§
- prelude
- Convenience re-exports
Structs§
- Dispatch
Result - Outcome of an event dispatch.
- Event
Dispatcher - High-performance event dispatcher
- Event
Metadata - Immutable snapshot of an event type’s metrics.
- Listener
Error - Opaque error returned by an event listener.
- Listener
Id - Unique identifier for event listeners
- Middleware
Manager - Middleware manager for event processing
Enums§
- Priority
- Priority levels for event listeners
Traits§
- Async
Event Listener - Trait for asynchronous event listeners.
- Event
- Core trait that all events must implement
- Event
Listener - Trait for synchronous event listeners
Type Aliases§
- Async
Event Result - Pinned future returned by an async listener.
- Middleware
Function - Middleware function type