SubscriberManager

Struct SubscriberManager 

pub struct SubscriberManager {
    subscribed: HashMap<String, Subscriber>,
    unsubscribed: HashSet<String>,
    close_tx: Option<Sender<()>>,
    channel_capacity: usize,
}

Fields§

§subscribed: HashMap<String, Subscriber>§unsubscribed: HashSet<String>§close_tx: Option<Sender<()>>§channel_capacity: usize

Implementations§

§

impl SubscriberManager

pub(crate) fn new(capacity: usize) -> Self

Creates a new SubscriberManager instance with the provided capacity. The capacity parameter sets the capacity of the broadcast channels used to distribute messages to subscribers. If capacity is 0, it is set to 1. If capacity is between 0 and usize::MAX / 2, it is used as is. If capacity is between usize::MAX / 2 + 1 and usize::MAX, it is set to usize::MAX / 2.

pub(crate) fn with_close_tx(close_tx: Sender<()>, capacity: usize) -> Self

Creates a new SubscriberManager instance with the provided close_tx and capacity. The close_tx parameter is a channel sender that can be used to signal the manager to close. The capacity parameter sets the capacity of the broadcast channels used to distribute messages to subscribers. If capacity is 0, it is set to 1. If capacity is between 0 and usize::MAX / 2, it is used as is. If capacity is between usize::MAX / 2 + 1 and usize::MAX, it is set to usize::MAX / 2.

pub(crate) fn sender(&self, topic: &str) -> Option<&Sender<Result<Publish>>>

Returns a reference to the Sender for the given topic, if the topic is currently subscribed.

pub(crate) fn receiver(&self, topic: &str) -> Option<Receiver<Result<Publish>>>

Returns a receiver for the given topic, if the topic is currently subscribed

pub(crate) fn qos(&self, topic: &str) -> Option<QoS>

Returns the Quality of Service (QoS) level for the given topic, if the topic is currently subscribed.

pub(crate) fn subscribed_diff<Iter>(&self, topics: Iter) -> Vec<String>
where Iter: IntoIterator, Iter::Item: AsRef<str>,

Returns an iterator over the topics that are not currently subscribed.

pub(crate) fn subscribe( &mut self, topic: &str, qos: QoS, ) -> Receiver<Result<Publish>>

pub(crate) fn subscribe_many<Iter>( &mut self, topics: Iter, qos: QoS, ) -> Vec<Receiver<Result<Publish>>>
where Iter: IntoIterator, Iter::Item: AsRef<str>,

pub(crate) fn unsubscribe(&mut self, topic: &str)

Removes the given topic from the list of subscribed topics and the list of unsubscribed topics.

pub(crate) fn schedule_unsubscribe(&mut self, topic: &str)

Schedules the unsubscription of the given topic.

pub(crate) fn schedule_unsubscribe_many<Iter>(&mut self, topics: Iter)
where Iter: IntoIterator, Iter::Item: AsRef<str>,

Schedules the unsubscription of the given topics.

pub(crate) const fn scheduled(&self) -> &HashSet<String>

Returns a reference to the set of topics that have been scheduled for unsubscription.

pub(crate) fn subscribers( &self, ) -> impl Iterator<Item = &Sender<Result<Publish>>>

Returns an iterator over the senders that have subscribed to this manager.

pub(crate) fn topics_with_qos(&self) -> impl Iterator<Item = (&str, QoS)>

Returns an iterator over the topics that have been subscribed to, along with their associated QoS level.

pub(crate) const fn capacity(&self) -> usize

Returns the capacity of the channel used by this subscriber manager.

Trait Implementations§

§

impl Debug for SubscriberManager

§

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

Formats the value using the given formatter. Read more
§

impl Drop for SubscriberManager

§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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, 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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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