Skip to main content

BroadcastMap

Struct BroadcastMap 

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

Implements core functionalities for the BroadcastMap struct.

Source

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

pub fn insert<K>(&self, key: K, capacity: usize) -> Option<Broadcast<T>>
where K: AsRef<str>,

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 to str.
  • capacity - Maximum number of buffered messages.
§Returns
  • Option<Broadcast<T>> - Previous broadcast channel if replaced.
Source

pub fn receiver_count<K>(&self, key: K) -> Option<usize>
where K: AsRef<str>,

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

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

pub fn subscribe<K>(&self, key: K) -> Option<Receiver<T>>
where K: AsRef<str>,

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

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

pub fn subscribe_or_insert<K>(&self, key: K, capacity: usize) -> Receiver<T>
where K: AsRef<str>,

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

pub fn try_send<K>( &self, key: K, data: T, ) -> Result<Option<usize>, SendError<T>>
where K: AsRef<str>,

Attempts to send a message to the broadcast channel associated with the given key.

§Arguments
  • AsRef<str> - Key convertible to str.
  • T - Message to broadcast.
§Returns
  • Result<Option<ReceiverCount>, SendError<T>> - Send result with receiver count or error.
Source

pub fn send<K>(&self, key: K, data: T) -> Option<usize>
where K: AsRef<str>,

Sends a message to the broadcast channel associated with the given key.

§Arguments
  • AsRef<str> - Key convertible to str.
  • T - Message to broadcast.
§Returns
  • Option<ReceiverCount> - The receiver count if the channel exists.
§Panics

Panics if the send operation fails (e.g., if the channel is closed).

Source

pub fn unsubscribe<K>(&self, key: K) -> Option<Broadcast<T>>
where K: AsRef<str>,

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 to str.
§Returns
  • Option<Broadcast<T>> - The removed broadcast channel if it existed, or None if no channel was associated with the key.

Trait Implementations§

Source§

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

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 for BroadcastMap<T>
where T: Debug + BroadcastTrait,

Source§

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

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

impl<T> Default for BroadcastMap<T>

Provides a default implementation for BroadcastMap instances.

The default broadcast map is initialized as an empty DashMap.

Source§

fn default() -> BroadcastMap<T>

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> UnsafeUnpin 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> AnySend for T
where T: Any + Send,

Source§

impl<T> AnySendClone for T
where T: Any + Send + Clone,

Source§

impl<T> AnySendSync for T
where T: Any + Send + Sync,

Source§

impl<T> AnySendSyncClone for T
where T: Any + Send + Sync + Clone,

Source§

impl<T> AnySync for T
where T: Any + Sync,

Source§

impl<T> AnySyncClone for T
where T: Any + Sync + Clone,

Source§

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

Source§

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

Source§

impl<T> ErasedDestructor for T
where T: 'static,