pub struct BroadcastMap<T: BroadcastTrait>(/* private fields */);Expand description
Re-exports structs, traits, and types from the broadcast_map module.
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: BroadcastMapTrait> BroadcastMap<T>
Implements core functionalities for the BroadcastMap struct.
impl<T: BroadcastMapTrait> BroadcastMap<T>
Implements core functionalities for the BroadcastMap struct.
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new, empty BroadcastMap instance.
This is a convenience constructor that simply calls default().
§Returns
An empty BroadcastMap.
Sourcepub fn insert<K>(&self, key: K, capacity: Capacity) -> OptionBroadcast<T>where
K: ToString,
pub fn insert<K>(&self, key: K, capacity: Capacity) -> OptionBroadcast<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
key- The key (convertible toString) to associate with the new broadcast channel.capacity- The maximum number of messages that can be buffered in the new broadcast channel.
§Returns
An Option containing the old Broadcast channel if one was replaced, otherwise None.
Sourcepub fn receiver_count<K>(&self, key: K) -> OptionReceiverCountwhere
K: ToString,
pub fn receiver_count<K>(&self, key: K) -> OptionReceiverCountwhere
K: ToString,
Sourcepub fn subscribe<K>(&self, key: K) -> OptionBroadcastMapReceiver<T>where
K: ToString,
pub fn subscribe<K>(&self, key: K) -> OptionBroadcastMapReceiver<T>where
K: ToString,
Sourcepub fn subscribe_or_insert<K>(
&self,
key: K,
capacity: Capacity,
) -> BroadcastMapReceiver<T>where
K: ToString,
pub fn subscribe_or_insert<K>(
&self,
key: K,
capacity: Capacity,
) -> BroadcastMapReceiver<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
key- The key (convertible toString) of the broadcast channel.capacity- The capacity to use if a new broadcast channel needs to be created.
§Returns
A BroadcastMapReceiver for the specified broadcast channel.
Sourcepub fn send<K>(&self, key: K, data: T) -> BroadcastMapSendResult<T>where
K: ToString,
pub fn send<K>(&self, key: K, data: T) -> BroadcastMapSendResult<T>where
K: ToString,
Sends a message to the broadcast channel associated with the given key.
§Arguments
key- The key (convertible toString) of the broadcast channel.data- The message to be broadcasted.
§Returns
A BroadcastMapSendResult indicating the number of receivers the message was sent to (if the channel exists),
or an error if the send operation failed. If the channel does not exist, Ok(None) is returned.
Trait Implementations§
Source§impl<T: Clone + BroadcastTrait> Clone for BroadcastMap<T>
impl<T: Clone + BroadcastTrait> Clone for BroadcastMap<T>
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 + BroadcastTrait> Debug for BroadcastMap<T>
impl<T: Debug + BroadcastTrait> Debug for BroadcastMap<T>
Source§impl<T: BroadcastMapTrait> Default for BroadcastMap<T>
Provides a default implementation for BroadcastMap instances.
impl<T: BroadcastMapTrait> Default for BroadcastMap<T>
Provides a default implementation for BroadcastMap instances.
The default broadcast map is initialized as an empty DashMap.