SubscriberManager

Struct SubscriberManager 

pub struct SubscriberManager {
    subscribers: TopicFilterMap<SubscriberSender>,
    close_tx: Option<Sender<()>>,
    channel_capacity: usize,
}

Fields§

§subscribers: TopicFilterMap<SubscriberSender>§close_tx: Option<Sender<()>>§channel_capacity: usize

Implementations§

§

impl SubscriberManager

pub const 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 fn with_close_tx(self, close_tx: Sender<()>) -> Self

Sets the close_tx channel sender for this subscriber manager.

fn subscribe_inner( &mut self, topic_filter: &TopicFilter<str>, qos: QoS, ) -> &mut SubscriberSender

pub fn subscribe( &mut self, topic_filter: &TopicFilter<str>, qos: QoS, ) -> StdResult<Subscriber, Subscriber>

Subscribes to the given topic filter.

Returns Ok if the subscription needs to be created, or Err if the subscription already exists and is active. If the caller receives Ok, it’s their responsibility to actually send the subscription request to the broker and to confirm the subscription to the manager.

pub fn subscribe_many( &mut self, topic_filters: impl IntoIterator<Item = impl AsRef<str>>, qos: QoS, ) -> (Subscriber, Vec<TopicFilter<Box<str>>>)

Subscribes to multiple topic filters at once.

Returns a tuple containing the subscriber and a list of topic filters that are yet to be subscribed. It’s the caller’s responsibility to subscribe to these filters and confirm the subscription to the manager.

pub fn route_publish(&mut self, publish: &Publish)

Routes a publish message to all matching subscribers.

pub fn broadcast_error(&mut self, error: Error)

Sends the given error to all subscribers.

pub fn mark_all_subscriptions_as_pending(&mut self)

Marks all subscriptions as pending.

pub fn confirm_subscribe(&mut self, topic_filter: &TopicFilter<str>)

Confirms that a given topic filter has been subscribed to.

pub fn confirm_unsubscribe(&mut self, topic_filter: &TopicFilter<str>)

Confirms that a given topic filter has been unsubscribed.

At this point we can fully remove the subscriber from the manager.

pub fn schedule_unsubscribe(&mut self, topic_filter: &TopicFilter<str>)

Schedules the unsubscription of the given topic.

pub fn schedule_unsubscribe_many<It>(&mut self, topic_filters: It)
where It: IntoIterator, It::Item: AsRef<str>,

Schedules the unsubscription of the given topics.

pub fn perform_pending_operations(&mut self, client: &AsyncClient)

Performs any pending subscribe or unsubscribe operations on the client.

The function tries to queue as many operations as possible into the client, stopping only once the client starts rejecting operations (most likely because the queue is full). All queued operations are then confirmed, so that the next time this function is called, only new or remaining pending operations will be processed.

This should only be called if the client is connected.

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