pub struct EventBus { /* private fields */ }Expand description
A publish-subscribe event bus for decoupled inter-entity communication.
Entities and game systems can subscribe to named event channels and emit events that are dispatched to all registered handlers.
Implementations§
Source§impl EventBus
Implements event subscription, emission, and management for EventBus.
impl EventBus
Implements event subscription, emission, and management for EventBus.
Sourcepub fn subscribe(&mut self, event_name: String, handler: EventHandler)
pub fn subscribe(&mut self, event_name: String, handler: EventHandler)
Subscribes a handler to the named event channel.
§Arguments
String- The event name to subscribe to.EventHandler- The handler closure to call when the event is emitted.
Sourcepub fn emit(&self, event: &EntityEvent)
pub fn emit(&self, event: &EntityEvent)
Emits an event to all handlers subscribed to the matching channel.
The event name is derived from the EntityEvent variant.
§Arguments
&EntityEvent- The event to emit.
Sourcepub fn unsubscribe_all(&mut self, event_name: &str)
pub fn unsubscribe_all(&mut self, event_name: &str)
Source§impl EventBus
impl EventBus
pub fn get_handlers(&self) -> &EventHandlers
pub fn set_handlers(&mut self, val: EventHandlers) -> &mut Self
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for EventBus
impl !Send for EventBus
impl !Sync for EventBus
impl !UnwindSafe for EventBus
impl Freeze for EventBus
impl Unpin for EventBus
impl UnsafeUnpin for EventBus
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more