pub struct RoomManager { /* private fields */ }Expand description
Manages named rooms with membership, presence, and broadcasting.
Rooms are created lazily on first join and removed when the last member leaves. Each room tracks its members, their ephemeral state (typing, cursors, custom data), and supports topic-scoped broadcasting.
Implementations§
Source§impl RoomManager
impl RoomManager
pub fn new(idle_timeout_secs: u64) -> Self
Sourcepub fn with_max_rooms(idle_timeout_secs: u64, max_rooms: usize) -> Self
pub fn with_max_rooms(idle_timeout_secs: u64, max_rooms: usize) -> Self
Create a RoomManager with a custom maximum room limit.
Sourcepub fn join(
&self,
room: &str,
user_id: &str,
data: Option<Value>,
) -> Result<(RoomEvent, RoomEvent), RoomError>
pub fn join( &self, room: &str, user_id: &str, data: Option<Value>, ) -> Result<(RoomEvent, RoomEvent), RoomError>
Join a room. Creates the room if it doesn’t exist. Returns a snapshot of current peers (before this join) and the join event, or an error if the room limit has been reached and this would create a new room.
Sourcepub fn leave(&self, room: &str, user_id: &str) -> Option<RoomEvent>
pub fn leave(&self, room: &str, user_id: &str) -> Option<RoomEvent>
Leave a room. Removes the room if it becomes empty. Returns the leave event, or None if the user wasn’t in the room.
Sourcepub fn set_presence(
&self,
room: &str,
user_id: &str,
data: Value,
) -> Option<RoomEvent>
pub fn set_presence( &self, room: &str, user_id: &str, data: Value, ) -> Option<RoomEvent>
Update a member’s ephemeral state (typing indicator, cursor position, etc.). Returns a presence event, or None if not in the room.
Sourcepub fn get_presence(&self, room: &str, user_id: &str) -> Option<Value>
pub fn get_presence(&self, room: &str, user_id: &str) -> Option<Value>
Get a member’s current ephemeral data.
Sourcepub fn broadcast(
&self,
room: &str,
sender: Option<&str>,
topic: &str,
data: Value,
) -> Option<RoomEvent>
pub fn broadcast( &self, room: &str, sender: Option<&str>, topic: &str, data: Value, ) -> Option<RoomEvent>
Broadcast an arbitrary event to a room. Returns the broadcast event, or None if the room doesn’t exist.
Sourcepub fn list_rooms(&self) -> Vec<String>
pub fn list_rooms(&self) -> Vec<String>
List all active room names.
Sourcepub fn is_in_room(&self, room: &str, user_id: &str) -> bool
pub fn is_in_room(&self, room: &str, user_id: &str) -> bool
Check if a user is in a specific room.
Sourcepub fn disconnect(&self, user_id: &str) -> Vec<RoomEvent>
pub fn disconnect(&self, user_id: &str) -> Vec<RoomEvent>
Remove a user from ALL rooms they’re in. Returns leave events.
Sourcepub fn cleanup_idle(&self) -> Vec<RoomEvent>
pub fn cleanup_idle(&self) -> Vec<RoomEvent>
Remove idle members from all rooms. Returns leave events for each removed member.
Sourcepub fn user_rooms(&self, user_id: &str) -> Vec<String>
pub fn user_rooms(&self, user_id: &str) -> Vec<String>
Get all rooms a user is currently in.
Trait Implementations§
Source§impl RoomOps for RoomManager
impl RoomOps for RoomManager
fn join( &self, room: &str, user_id: &str, data: Option<Value>, ) -> Result<(Value, Value), DataError>
fn leave(&self, room: &str, user_id: &str) -> Option<Value>
fn set_presence(&self, room: &str, user_id: &str, data: Value) -> Option<Value>
fn broadcast( &self, room: &str, sender: Option<&str>, topic: &str, data: Value, ) -> Option<Value>
fn list_rooms(&self) -> Vec<String>
fn room_size(&self, name: &str) -> usize
fn members(&self, name: &str) -> Vec<Value>
Auto Trait Implementations§
impl !Freeze for RoomManager
impl RefUnwindSafe for RoomManager
impl Send for RoomManager
impl Sync for RoomManager
impl Unpin for RoomManager
impl UnsafeUnpin for RoomManager
impl UnwindSafe for RoomManager
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
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>
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>
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 moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);