Trait Event

Source
pub trait Event:
    Any
    + Send
    + Sync
    + Debug {
    // Required method
    fn as_any(&self) -> &dyn Any;

    // Provided methods
    fn type_id(&self) -> TypeId { ... }
    fn event_name(&self) -> &'static str { ... }
}
Expand description

Core trait that all events must implement

This trait provides the foundation for type-safe event dispatch. All event types must implement this trait to be used with the dispatcher.

§Example

use mod_events::Event;

#[derive(Debug, Clone)]
struct UserRegistered {
    user_id: u64,
    email: String,
}

impl Event for UserRegistered {
    fn as_any(&self) -> &dyn std::any::Any {
        self
    }
}

Required Methods§

Source

fn as_any(&self) -> &dyn Any

Returns the event as Any for downcasting

Provided Methods§

Source

fn type_id(&self) -> TypeId

Returns a unique identifier for this event type

Source

fn event_name(&self) -> &'static str

Returns the event name for debugging

Implementors§