Skip to main content

Crate mod_events

Crate mod_events 

Source
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/.await compatibility (with the async feature).
  • 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§

DispatchResult
Outcome of an event dispatch.
EventDispatcher
High-performance event dispatcher
EventMetadata
Immutable snapshot of an event type’s metrics.
ListenerError
Opaque error returned by an event listener.
ListenerId
Unique identifier for event listeners
MiddlewareManager
Middleware manager for event processing

Enums§

Priority
Priority levels for event listeners

Traits§

AsyncEventListener
Trait for asynchronous event listeners.
Event
Core trait that all events must implement
EventListener
Trait for synchronous event listeners

Type Aliases§

AsyncEventResult
Pinned future returned by an async listener.
MiddlewareFunction
Middleware function type