pub struct WsHub<T: Clone + Send + 'static> { /* private fields */ }Expand description
Hub that fans messages out to every connected WebSocket. Cheap to
clone — internally an Arc<broadcast::Sender> plus config.
Implementations§
Source§impl<T: Clone + Send + Serialize + 'static> WsHub<T>
impl<T: Clone + Send + Serialize + 'static> WsHub<T>
pub fn new(bus: EventBus<T>) -> Self
pub fn with_config(bus: EventBus<T>, config: WsConfig) -> Self
Sourcepub fn keepalive(self, interval: Duration) -> Self
pub fn keepalive(self, interval: Duration) -> Self
Override the keepalive interval. Lower = better dead-connection detection, higher = less network chatter. Default: 30 seconds.
Sourcepub fn on_message(self, f: fn(&str) -> Option<String>) -> Self
pub fn on_message(self, f: fn(&str) -> Option<String>) -> Self
Set a per-message text handler. Returning Some(reply) echoes
back to the originating client only (NOT a broadcast). Use the
hub’s Self::broadcast for fan-out from the handler if needed.
pub fn max_message_bytes(self, n: usize) -> Self
Sourcepub fn broadcast(&self, event: T) -> usize
pub fn broadcast(&self, event: T) -> usize
Send event to every currently connected client. Drops with no
effect when zero clients are connected. Returns the number of
receivers that observed the send.
pub fn receiver_count(&self) -> usize
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for WsHub<T>
impl<T> RefUnwindSafe for WsHub<T>where
EventBus<T>: RefUnwindSafe,
impl<T> Send for WsHub<T>
impl<T> Sync for WsHub<T>
impl<T> Unpin for WsHub<T>
impl<T> UnsafeUnpin for WsHub<T>where
EventBus<T>: UnsafeUnpin,
impl<T> UnwindSafe for WsHub<T>where
EventBus<T>: 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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