Struct BroadcastMap

Source
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.

Source

pub fn new() -> Self

Creates a new, empty BroadcastMap instance.

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

§Returns

An empty BroadcastMap.

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
  • key - The key (convertible to String) 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.

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
  • key - The key (convertible to String) of the broadcast channel.
§Returns

An Option containing the ReceiverCount if the broadcast channel exists, otherwise None.

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
  • key - The key (convertible to String) of the broadcast channel.
§Returns

An Option containing a BroadcastMapReceiver if the broadcast channel exists, otherwise None.

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
  • key - The key (convertible to String) 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.

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
  • key - The key (convertible to String) 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>

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

An empty BroadcastMap.

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<T> BroadcastMapTrait for T
where T: Clone + Debug,

Source§

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