Struct BroadcastMap

Source
pub struct BroadcastMap<T: BroadcastTrait>(/* private fields */);
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: BroadcastMapTrait> BroadcastMap<T>

Implements core functionalities for the BroadcastMap struct.

Source

pub fn new() -> Self

Creates a new, empty BroadcastMap instance.

This is a convenience constructor that simply calls default().

§Returns
  • BroadcastMap<T> - An empty broadcast map.
Source

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
  • K - Key convertible to String.
  • Capacity - Maximum number of buffered messages.
§Returns
  • Option<Broadcast<T>> - Previous broadcast channel if replaced.
Source

pub fn receiver_count<K>(&self, key: K) -> OptionReceiverCount
where K: ToString,

Retrieves the number of active receivers for the broadcast channel associated with the given key.

§Arguments
  • K - Key convertible to String.
§Returns
  • Option<ReceiverCount> - Number of receivers if channel exists.
Source

pub fn subscribe<K>(&self, key: K) -> OptionBroadcastMapReceiver<T>
where K: ToString,

Subscribes a new receiver to the broadcast channel associated with the given key.

§Arguments
  • K - Key convertible to String.
§Returns
  • Option<BroadcastReceiver<T>> - New receiver if channel exists.
Source

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
  • K - Key convertible to String.
  • Capacity - Capacity for new channel if needed.
§Returns
  • BroadcastReceiver<T> - New receiver for the channel.
Source

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
  • K - Key convertible to String.
  • T - Message to broadcast.
§Returns
  • Result<Option<ReceiverCount>, SendError<T>> - Send result with receiver count or error.

Trait Implementations§

Source§

impl<T: Clone + BroadcastTrait> Clone for BroadcastMap<T>

Source§

fn clone(&self) -> BroadcastMap<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + BroadcastTrait> Debug for BroadcastMap<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: BroadcastMapTrait> Default for BroadcastMap<T>

Provides a default implementation for BroadcastMap instances.

The default broadcast map is initialized as an empty DashMap.

Source§

fn default() -> Self

Creates a new, empty BroadcastMap instance.

§Returns
  • BroadcastMap<T> - An empty broadcast map.

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> !UnwindSafe for BroadcastMap<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> BroadcastMapTrait for T
where T: Clone + Debug,

Source§

impl<T> BroadcastTrait for T
where T: Clone + Debug,