pub struct EventBus { /* private fields */ }Expand description
事件总线
Implementations§
Source§impl EventBus
impl EventBus
pub fn new() -> Self
Sourcepub fn subscribe<F>(&self, event_type: &str, handler: F) -> HandlerId
pub fn subscribe<F>(&self, event_type: &str, handler: F) -> HandlerId
订阅事件,返回 handler ID 用于取消订阅
Sourcepub fn unsubscribe(&self, event_type: &str, handler_id: HandlerId) -> bool
pub fn unsubscribe(&self, event_type: &str, handler_id: HandlerId) -> bool
取消订阅
Sourcepub fn unsubscribe_all(&self, event_type: &str) -> usize
pub fn unsubscribe_all(&self, event_type: &str) -> usize
取消某事件类型的所有订阅
Sourcepub fn subscriber_count(&self, event_type: &str) -> usize
pub fn subscriber_count(&self, event_type: &str) -> usize
获取某事件类型的订阅数量
Sourcepub fn total_subscribers(&self) -> usize
pub fn total_subscribers(&self) -> usize
获取所有事件类型的订阅总数
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for EventBus
impl !RefUnwindSafe for EventBus
impl !UnwindSafe for EventBus
impl Send for EventBus
impl Sync 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