Skip to main content

Room

Struct Room 

Source
pub struct Room {
    pub id: String,
    /* private fields */
}
Expand description

A single broadcast room with a participant roster.

Fields§

§id: String

Room identifier.

Implementations§

Source§

impl Room

Source

pub fn new(id: impl Into<String>, capacity: usize) -> Self

Create a new room with the given id and broadcast capacity.

Source

pub fn with_stats( id: impl Into<String>, capacity: usize, stats: Option<StatsRecorder>, ) -> Self

Create a new room that records outbound traffic and drops into stats (0.4.0 backpressure hook — see crate::stats).

Source

pub fn subscribe(&self) -> Receiver<Frame>

Subscribe to this room’s messages (text and binary).

Source

pub fn broadcast(&self, msg: impl Into<Frame>) -> Result<usize, WsError>

Broadcast a frame (text or binary) to all participants.

Accepts anything Frame converts from — String, &str, bytes::Bytes, Vec<u8> — with no re-encoding for owned payloads.

§Errors

Returns WsError::BroadcastFull when the room has no active receivers; with a StatsRecorder attached this also counts as a drop (backpressure loss).

Source

pub fn join(&self, participant_id: u32, name: String)

Add a participant (or refresh its display name on re-join).

Source

pub fn leave(&self, participant_id: u32) -> bool

Remove a participant. Returns true if it was present.

Source

pub fn contains(&self, participant_id: u32) -> bool

Check if participant is in room.

Source

pub fn participants(&self) -> Vec<(u32, String)>

Snapshot of (participant_id, name) pairs.

Source

pub fn participant_names(&self) -> Vec<String>

Snapshot of participant display names.

Source

pub fn participant_count(&self) -> usize

Number of tracked participants.

Source

pub fn receiver_count(&self) -> usize

Number of active broadcast receivers.

Source

pub fn is_empty(&self) -> bool

Returns true if no participants and no receivers.

Source

pub fn sender(&self) -> &Sender<Frame>

Internal sender.

Trait Implementations§

Source§

impl Debug for Room

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Room

§

impl !UnwindSafe for Room

§

impl Freeze for Room

§

impl Send for Room

§

impl Sync for Room

§

impl Unpin for Room

§

impl UnsafeUnpin for Room

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.