Skip to main content

Event

Trait Event 

Source
pub trait Event: Any + Send {
    // Required methods
    fn is_cancelled(&self) -> bool;
    fn cancel(&mut self);
    fn as_any(&self) -> &dyn Any;
    fn as_any_mut(&mut self) -> &mut dyn Any;
    fn bus_kind(&self) -> BusKind;
}
Expand description

Trait implemented by all game events.

Events carry domain data and support cancellation. The as_any methods enable type erasure inside the EventBus — handlers register for concrete types via TypeId, and the bus downcasts during dispatch.

Not all events are cancellable. For non-cancellable events (e.g., PlayerJoinedEvent), cancel() is a no-op and is_cancelled() always returns false.

Required Methods§

Source

fn is_cancelled(&self) -> bool

Whether this event has been cancelled by a Validate handler.

Source

fn cancel(&mut self)

Cancels this event. Process and Post handlers will be skipped.

Only meaningful during the Validate stage. Non-cancellable events ignore this call.

Source

fn as_any(&self) -> &dyn Any

Upcasts to &dyn Any for type-erased dispatch.

Source

fn as_any_mut(&mut self) -> &mut dyn Any

Upcasts to &mut dyn Any for mutable type-erased dispatch.

Source

fn bus_kind(&self) -> BusKind

Returns which event bus this event is dispatched on.

Enables runtime routing of type-erased events (&mut dyn Event) to the correct bus without hardcoded TypeId checks. Every event type declares its bus via the macros (instant_event!, game_event!, etc.).

Implementors§