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>
impl<M: Message> Subscription<M>
Sourcepub fn unregistered() -> Self
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.
Sourcepub fn new(msg_broker: Arc<dyn MessageBroker>) -> Self
pub fn new(msg_broker: Arc<dyn MessageBroker>) -> Self
Creates a new Subscription
which is registered in the given message broker.
Sourcepub fn recv_message(&self) -> Option<Arc<M>>
pub fn recv_message(&self) -> Option<Arc<M>>
Receives one message if there is any.
Sourcepub fn process_messages<F: FnMut(Arc<M>)>(&self, f: F)
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>
impl<M: Message> Default for Subscription<M>
Source§impl<M: Message> Drop for Subscription<M>
impl<M: Message> Drop for Subscription<M>
Source§impl<M: Message> ErasedSubscription for Subscription<M>
impl<M: Message> ErasedSubscription for Subscription<M>
Source§fn message_broker(&self) -> Option<Arc<dyn MessageBroker>>
fn message_broker(&self) -> Option<Arc<dyn MessageBroker>>
Returns a message broker which sends messages to this subscription.
Source§fn is_registered(&self) -> bool
fn is_registered(&self) -> bool
Returns if the subscription is registered.
Source§fn register(
&mut self,
msg_broker: Arc<dyn MessageBroker>,
) -> Result<(), SubscriptionError>
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>
fn unregister(&mut self) -> Result<(), SubscriptionError>
Unregisters the subscription in the given message broker.
Source§fn activate(&self) -> Result<(), SubscriptionError>
fn activate(&self) -> Result<(), SubscriptionError>
Activates the subscription if it was deactivated before.
Source§fn deactivate(&self) -> Result<(), SubscriptionError>
fn deactivate(&self) -> Result<(), SubscriptionError>
Dectivates the subscription, in other words temporary makes it stop receiving messages.
Source§fn message_iter(&self) -> MessageIter<'_> ⓘ
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>)
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more