Struct Subscription

Source
pub struct Subscription<M: Message> { /* private fields */ }
Expand description

A type which is used for receiving messages of a specific type from the message broker.

Implementations§

Source§

impl<M: Message> Subscription<M>

Source

pub fn unregistered() -> Self

Creates a new Subscription which is not registered in any message broker and therefore can’t be used for receiving messages.

Examples found in repository?
examples/simple.rs (line 41)
39    fn new() -> Self {
40        Self {
41            sub: Subscription::unregistered(),
42        }
43    }
Source

pub fn new(msg_broker: Arc<dyn MessageBroker>) -> Self

Creates a new Subscription which is registered in the given message broker.

Source

pub fn recv_message(&self) -> Option<Arc<M>>

Receives one message if there is any.

Source

pub fn process_messages<F: FnMut(Arc<M>)>(&self, f: F)

Processes all pending messages by calling the given function on each one.

Trait Implementations§

Source§

impl<M: Message> Default for Subscription<M>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<M: Message> Drop for Subscription<M>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<M: Message> ErasedSubscription for Subscription<M>

Source§

fn message_broker(&self) -> Option<Arc<dyn MessageBroker>>

Returns a message broker which sends messages to this subscription.
Source§

fn is_registered(&self) -> bool

Returns if the subscription is registered.
Source§

fn is_active(&self) -> bool

Returns if the subscription is active.
Source§

fn register( &mut self, msg_broker: Arc<dyn MessageBroker>, ) -> Result<(), SubscriptionError>

Registers the subscription in the given message broker.
Source§

fn unregister(&mut self) -> Result<(), SubscriptionError>

Unregisters the subscription in the given message broker.
Source§

fn activate(&self) -> Result<(), SubscriptionError>

Activates the subscription if it was deactivated before.
Source§

fn deactivate(&self) -> Result<(), SubscriptionError>

Dectivates the subscription, in other words temporary makes it stop receiving messages.
Source§

fn recv_message(&self) -> Option<Arc<dyn Message>>

Receives one message if there is any.
Source§

fn message_iter(&self) -> MessageIter<'_>

Returns an iterator that will attempt to yield all pending messages.
Source§

fn process_messages<'f>(&self, f: Box<dyn ErasedMessageHandler + 'f>)

Processes all pending messages by calling the given function on each one.

Auto Trait Implementations§

§

impl<M> Freeze for Subscription<M>

§

impl<M> !RefUnwindSafe for Subscription<M>

§

impl<M> !Send for Subscription<M>

§

impl<M> !Sync for Subscription<M>

§

impl<M> Unpin for Subscription<M>
where M: Unpin,

§

impl<M> !UnwindSafe for Subscription<M>

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.

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.