pub struct Room {
pub id: String,
/* private fields */
}Expand description
A single broadcast room with a participant roster.
Fields§
§id: StringRoom identifier.
Implementations§
Source§impl Room
impl Room
Sourcepub fn new(id: impl Into<String>, capacity: usize) -> Self
pub fn new(id: impl Into<String>, capacity: usize) -> Self
Create a new room with the given id and broadcast capacity.
Sourcepub fn broadcast(&self, msg: String) -> Result<usize, WsError>
pub fn broadcast(&self, msg: String) -> Result<usize, WsError>
Broadcast a text message to all participants.
Sourcepub fn join(&self, participant_id: u32, name: String)
pub fn join(&self, participant_id: u32, name: String)
Add a participant (or refresh its display name on re-join).
Sourcepub fn leave(&self, participant_id: u32) -> bool
pub fn leave(&self, participant_id: u32) -> bool
Remove a participant. Returns true if it was present.
Sourcepub fn participants(&self) -> Vec<(u32, String)>
pub fn participants(&self) -> Vec<(u32, String)>
Snapshot of (participant_id, name) pairs.
Sourcepub fn participant_names(&self) -> Vec<String>
pub fn participant_names(&self) -> Vec<String>
Snapshot of participant display names.
Sourcepub fn participant_count(&self) -> usize
pub fn participant_count(&self) -> usize
Number of tracked participants.
Sourcepub fn receiver_count(&self) -> usize
pub fn receiver_count(&self) -> usize
Number of active broadcast receivers.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Room
impl Freeze for Room
impl Send for Room
impl Sync for Room
impl Unpin for Room
impl UnsafeUnpin for Room
impl UnwindSafe for Room
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