pub struct EventBus<T: Clone + Send + 'static> { /* private fields */ }Expand description
Broadcast bus — fan one message out to every connected subscriber.
Slow consumers that fall behind the buffer get a RecvError::Lagged
and skip messages — they don’t block other subscribers. The default
buffer size is 100 messages.
Implementations§
Source§impl<T: Clone + Send + 'static> EventBus<T>
impl<T: Clone + Send + 'static> EventBus<T>
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
New bus with the given buffer capacity. Higher = more tolerance for slow consumers; lower = less memory pressure under heavy fan-out. Capacity floors at 1.
Sourcepub fn send(&self, event: T) -> usize
pub fn send(&self, event: T) -> usize
Send a message to every active subscriber. Returns the number of subscribers who received it (zero is fine — no-op when no clients are connected).
Sourcepub fn receiver_count(&self) -> usize
pub fn receiver_count(&self) -> usize
Number of currently active subscribers.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for EventBus<T>
impl<T> RefUnwindSafe for EventBus<T>
impl<T> Send for EventBus<T>
impl<T> Sync for EventBus<T>
impl<T> Unpin for EventBus<T>
impl<T> UnsafeUnpin for EventBus<T>
impl<T> UnwindSafe for EventBus<T>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more