pub struct BroadcastMap<T>(/* private fields */)
where
T: BroadcastTrait;Expand description
Represents a concurrent, thread-safe map of broadcast channels, keyed by string.
This struct provides a way to manage multiple broadcast channels, each identified by a unique string, allowing for dynamic creation, retrieval, and management of broadcast streams.
Implementations§
Source§impl<T> BroadcastMap<T>where
T: BroadcastMapTrait,
Implements core functionalities for the BroadcastMap struct.
impl<T> BroadcastMap<T>where
T: BroadcastMapTrait,
Implements core functionalities for the BroadcastMap struct.
Sourcepub fn new() -> BroadcastMap<T>
pub fn new() -> BroadcastMap<T>
Creates a new, empty BroadcastMap instance.
This is a convenience constructor that simply calls default().
§Returns
BroadcastMap<T>- An empty broadcast map.
Sourcepub fn insert<K>(&self, key: K, capacity: usize) -> Option<Broadcast<T>>
pub fn insert<K>(&self, key: K, capacity: usize) -> Option<Broadcast<T>>
Inserts a new broadcast channel into the map with a specified key and capacity.
If a broadcast channel with the given key already exists, it will be replaced.
§Arguments
AsRef<str>- Key convertible tostr.capacity- Maximum number of buffered messages.
§Returns
Option<Broadcast<T>>- Previous broadcast channel if replaced.
Sourcepub fn receiver_count<K>(&self, key: K) -> Option<usize>
pub fn receiver_count<K>(&self, key: K) -> Option<usize>
Sourcepub fn subscribe_or_insert<K>(&self, key: K, capacity: usize) -> Receiver<T>
pub fn subscribe_or_insert<K>(&self, key: K, capacity: usize) -> Receiver<T>
Subscribes a new receiver to the broadcast channel associated with the given key. If the channel does not exist, it will be created with the specified capacity before subscribing.
§Arguments
AsRef<str>- Key convertible tostr.capacity- Capacity for new channel if needed.
§Returns
BroadcastReceiver<T>- New receiver for the channel.
Sourcepub fn unsubscribe<K>(&self, key: K) -> Option<Broadcast<T>>
pub fn unsubscribe<K>(&self, key: K) -> Option<Broadcast<T>>
Unsubscribes and removes the broadcast channel associated with the given key from the map.
This operation effectively cancels all subscriptions to the channel by removing it from the map. Any existing receivers will no longer receive new messages, and the channel will be dropped.
§Arguments
AsRef<str>- Key convertible tostr.
§Returns
Option<Broadcast<T>>- The removed broadcast channel if it existed, orNoneif no channel was associated with the key.
Trait Implementations§
Source§impl<T> Clone for BroadcastMap<T>where
T: Clone + BroadcastTrait,
impl<T> Clone for BroadcastMap<T>where
T: Clone + BroadcastTrait,
Source§fn clone(&self) -> BroadcastMap<T>
fn clone(&self) -> BroadcastMap<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T> Debug for BroadcastMap<T>where
T: Debug + BroadcastTrait,
impl<T> Debug for BroadcastMap<T>where
T: Debug + BroadcastTrait,
Source§impl<T> Default for BroadcastMap<T>where
T: BroadcastMapTrait,
Provides a default implementation for BroadcastMap instances.
impl<T> Default for BroadcastMap<T>where
T: BroadcastMapTrait,
Provides a default implementation for BroadcastMap instances.
The default broadcast map is initialized as an empty DashMap.
Source§fn default() -> BroadcastMap<T>
fn default() -> BroadcastMap<T>
Auto Trait Implementations§
impl<T> Freeze for BroadcastMap<T>
impl<T> !RefUnwindSafe for BroadcastMap<T>
impl<T> Send for BroadcastMap<T>where
T: Send,
impl<T> Sync for BroadcastMap<T>where
T: Send,
impl<T> Unpin for BroadcastMap<T>
impl<T> UnsafeUnpin for BroadcastMap<T>
impl<T> !UnwindSafe for BroadcastMap<T>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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