pub struct EventBus<E: Clone + Send + 'static> { /* private fields */ }Expand description
Multi-producer multi-consumer event bus. Cheap to clone — the
inner broadcast::Sender is Arc-backed.
Implementations§
Source§impl<E: Clone + Send + 'static> EventBus<E>
impl<E: Clone + Send + 'static> EventBus<E>
Sourcepub fn new() -> Self
pub fn new() -> Self
New bus with DEFAULT_CAPACITY.
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
New bus with explicit capacity. Clamped to at least 1.
Sourcepub fn publish(&self, event: E)
pub fn publish(&self, event: E)
Publish event. Returns silently when there are zero
receivers — by design, no listeners is not an error from the
publisher’s perspective.
Sourcepub fn subscribe(&self) -> Receiver<E>
pub fn subscribe(&self) -> Receiver<E>
Subscribe to events. Each receiver sees every event emitted from the moment of subscription forward.
Sourcepub fn subscriber_count(&self) -> usize
pub fn subscriber_count(&self) -> usize
Live subscriber count. Useful for skipping notification work when nobody is listening (cheap optimisation in mutation paths).
Trait Implementations§
Auto Trait Implementations§
impl<E> Forget for EventBus<E>
impl<E> Freeze for EventBus<E>
impl<E> Move for EventBus<E>
impl<E> RefUnwindSafe for EventBus<E>where
Atomic<usize>: RefUnwindSafe,
Mutex<Slot<E>>: RefUnwindSafe,
Mutex<Tail>: RefUnwindSafe,
AtomicUsize: RefUnwindSafe,
Notify: RefUnwindSafe,
impl<E> Send for EventBus<E>
impl<E> Sync for EventBus<E>
impl<E> Unpin for EventBus<E>
impl<E> UnsafeUnpin for EventBus<E>where
*const ArcInner<Shared<E>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Shared<E>>>: UnsafeUnpin,
impl<E> UnwindSafe for EventBus<E>where
Arc<Shared<E>>: UnwindSafe,
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