Skip to main content

SubscriberOps

Trait SubscriberOps 

Source
pub trait SubscriberOps {
    type Subscriber: MutEventSubscriber;

    // Required methods
    fn add_subscriber(&mut self, subscriber: Self::Subscriber) -> SubscriberId;
    fn remove_subscriber(
        &mut self,
        subscriber_id: SubscriberId,
    ) -> Result<Self::Subscriber, Error>;
    fn subscriber_mut(
        &mut self,
        subscriber_id: SubscriberId,
    ) -> Result<&mut Self::Subscriber, Error>;
    fn event_ops(
        &mut self,
        subscriber_id: SubscriberId,
    ) -> Result<EventOps<'_>, Error>;
}
Expand description

API that allows users to add, remove, and interact with registered subscribers.

Required Associated Types§

Source

type Subscriber: MutEventSubscriber

Subscriber type for which the operations apply.

Required Methods§

Source

fn add_subscriber(&mut self, subscriber: Self::Subscriber) -> SubscriberId

Registers a new subscriber and returns the ID associated with it.

§Panics

This function might panic if the subscriber is already registered. Whether a panic is triggered depends on the implementation of Subscriber::init().

Typically, in the init function, the subscriber adds fds to its interest list. The same fd cannot be added twice and the EventManager will return Error::FdAlreadyRegistered. Using unwrap in init in this situation triggers a panic.

Source

fn remove_subscriber( &mut self, subscriber_id: SubscriberId, ) -> Result<Self::Subscriber, Error>

Removes the subscriber corresponding to subscriber_id from the watch list.

Source

fn subscriber_mut( &mut self, subscriber_id: SubscriberId, ) -> Result<&mut Self::Subscriber, Error>

Returns a mutable reference to the subscriber corresponding to subscriber_id.

Source

fn event_ops( &mut self, subscriber_id: SubscriberId, ) -> Result<EventOps<'_>, Error>

Creates an event operations wrapper for the subscriber corresponding to subscriber_id.

The event operations can be used to update the events monitored by the subscriber.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§