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§
Provided Methods§
Sourcefn type_id(&self) -> TypeId
fn type_id(&self) -> TypeId
Returns the unique TypeId identifier for this event type.
Equivalent to <Self as Any>::type_id(self) since Event
requires the Any supertrait. Both methods are available and
return identical values; this one is provided for ergonomics
when working with &dyn Event trait objects, where the
supertrait method requires a &dyn Any cast first.
Sourcefn event_name(&self) -> &'static str
fn event_name(&self) -> &'static str
Returns the event name for debugging / logging.
Backed by std::any::type_name. The exact format is
not stable across compiler versions — the Rust standard
library reserves the right to change type_name output
between releases. Treat the result as opaque human-readable
text. Do not parse it, persist it, or use it as a stable
cross-process identifier; use Event::type_id for that
instead.