pub struct Rooms { /* private fields */ }Expand description
Every socket currently connected, grouped by a key you choose.
The thing every non-trivial socket application needs and none of them want to write twice: a chat needs the room’s members, a live dashboard needs everyone watching one account.
ⓘ
rooms.join("lobby", socket.clone());
rooms.send("lobby", Message::text("someone arrived"));
rooms.leave("lobby", socket.id());Handles to sockets that have gone away are dropped on the next send rather than reaped on a timer, so a client that vanished without a close frame costs one failed send and then nothing.
Implementations§
Source§impl Rooms
impl Rooms
Sourcepub fn leave_all(&self, socket: SocketId)
pub fn leave_all(&self, socket: SocketId)
Remove a socket from every room.
What on_close should call: a handler that tracked which rooms a
socket was in would be keeping a second copy of this map.
Sourcepub fn send(&self, room: &str, message: impl Into<Message>) -> usize
pub fn send(&self, room: &str, message: impl Into<Message>) -> usize
Send to everyone in room. Returns how many received it.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Rooms
impl RefUnwindSafe for Rooms
impl Send for Rooms
impl Sync for Rooms
impl Unpin for Rooms
impl UnsafeUnpin for Rooms
impl UnwindSafe for Rooms
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