pub struct SubscriptionManager { /* private fields */ }Expand description
Thread-safe subscription manager with two-level indexing.
Level 1: entity → set of connection IDs (for fan-out). Level 2: connection → map of entity → subscription details (for per-connection state).
Implementations§
Source§impl SubscriptionManager
impl SubscriptionManager
Sourcepub fn new(max_per_entity: usize) -> Self
pub fn new(max_per_entity: usize) -> Self
Create a new subscription manager with the given fan-out limit.
Sourcepub fn subscribe(
&self,
connection_id: &str,
entity: &str,
details: SubscriptionDetails,
) -> Result<bool, String>
pub fn subscribe( &self, connection_id: &str, entity: &str, details: SubscriptionDetails, ) -> Result<bool, String>
Subscribe a connection to an entity.
Returns Ok(true) if this is a new subscription, Ok(false) if the
connection was already subscribed (idempotent).
§Errors
Returns an error if the fan-out limit for this entity is reached.
Sourcepub fn unsubscribe(&self, connection_id: &str, entity: &str) -> bool
pub fn unsubscribe(&self, connection_id: &str, entity: &str) -> bool
Unsubscribe a connection from an entity.
Returns true if the subscription existed and was removed.
Sourcepub fn unsubscribe_all(&self, connection_id: &str)
pub fn unsubscribe_all(&self, connection_id: &str)
Remove all subscriptions for a connection (called on disconnect).
Sourcepub fn count_for_entity(&self, entity: &str) -> usize
pub fn count_for_entity(&self, entity: &str) -> usize
Number of subscriptions for a given entity.
Sourcepub fn count_for_connection(&self, connection_id: &str) -> usize
pub fn count_for_connection(&self, connection_id: &str) -> usize
Number of entities a connection is subscribed to.
Sourcepub fn get_subscribers(
&self,
entity: &str,
) -> Option<Vec<(ConnectionId, SubscriptionDetails)>>
pub fn get_subscribers( &self, entity: &str, ) -> Option<Vec<(ConnectionId, SubscriptionDetails)>>
Get all subscribers for an entity with their subscription details.
Returns a vec of (connection_id, details) pairs, or None if no
connections are subscribed to this entity.
Auto Trait Implementations§
impl !RefUnwindSafe for SubscriptionManager
impl Freeze for SubscriptionManager
impl Send for SubscriptionManager
impl Sync for SubscriptionManager
impl Unpin for SubscriptionManager
impl UnsafeUnpin for SubscriptionManager
impl UnwindSafe for SubscriptionManager
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
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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