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>>where
K: ToString,
pub fn insert<K>(&self, key: K, capacity: usize) -> Option<Broadcast<T>>where
K: ToString,
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
K
- Key convertible toString
.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>where
K: ToString,
pub fn receiver_count<K>(&self, key: K) -> Option<usize>where
K: ToString,
Sourcepub fn subscribe_or_insert<K>(&self, key: K, capacity: usize) -> Receiver<T>where
K: ToString,
pub fn subscribe_or_insert<K>(&self, key: K, capacity: usize) -> Receiver<T>where
K: ToString,
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
K
- Key convertible toString
.Capacity
- Capacity for new channel if needed.
§Returns
BroadcastReceiver<T>
- New receiver for the channel.
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
.