pub struct PresenceManager { /* private fields */ }Expand description
Manages room-based presence state.
Thread-safe via RwLock for the room map and atomics for counters.
Implementations§
Source§impl PresenceManager
impl PresenceManager
Sourcepub fn new(config: PresenceConfig) -> Self
pub fn new(config: PresenceConfig) -> Self
Create a new presence manager.
Sourcepub async fn join(
&self,
room: &str,
member_id: &str,
state: Value,
) -> Result<(PresenceState, PresenceDiff), PresenceError>
pub async fn join( &self, room: &str, member_id: &str, state: Value, ) -> Result<(PresenceState, PresenceDiff), PresenceError>
Join a room with initial state.
Returns PresenceState (current members including the new one) and
a PresenceDiff (announcing the join) for broadcasting.
§Errors
Returns error if the room is full or room limit is exceeded.
Sourcepub async fn leave(&self, room: &str, member_id: &str) -> Option<PresenceDiff>
pub async fn leave(&self, room: &str, member_id: &str) -> Option<PresenceDiff>
Leave a room.
Returns a PresenceDiff for broadcasting, or None if the member
wasn’t in the room.
Sourcepub async fn heartbeat(&self, room: &str, member_id: &str) -> bool
pub async fn heartbeat(&self, room: &str, member_id: &str) -> bool
Record a heartbeat for a member, resetting their eviction timer.
Returns true if the heartbeat was accepted (member exists in room).
Sourcepub async fn update_state(
&self,
room: &str,
member_id: &str,
new_state: Value,
) -> Option<PresenceDiff>
pub async fn update_state( &self, room: &str, member_id: &str, new_state: Value, ) -> Option<PresenceDiff>
Update a member’s state payload.
Returns a PresenceDiff with the updated member in joins (same
semantics as Supabase Realtime — updates appear as joins).
Sourcepub async fn evict_stale(&self) -> Vec<PresenceDiff>
pub async fn evict_stale(&self) -> Vec<PresenceDiff>
Evict members whose heartbeat has expired.
Returns PresenceDiff events for each room that had evictions.
Sourcepub async fn get_room(&self, room: &str) -> Option<PresenceState>
pub async fn get_room(&self, room: &str) -> Option<PresenceState>
Get current members of a room.
Sourcepub async fn stats(&self) -> PresenceStats
pub async fn stats(&self) -> PresenceStats
Get statistics.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for PresenceManager
impl !RefUnwindSafe for PresenceManager
impl Send for PresenceManager
impl Sync for PresenceManager
impl Unpin for PresenceManager
impl UnsafeUnpin for PresenceManager
impl UnwindSafe for PresenceManager
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 more