Skip to main content

SubjectActor

Trait SubjectActor 

Source
pub trait SubjectActor<Event>: Actor
where Event: Message + Clone,
{ // Required method fn observers_mut(&mut self) -> &mut ObserverSet<Event>; // Provided methods fn register_observer(&mut self, observer: Recipient<Event>) { ... } fn unregister_observer(&mut self, observer: Recipient<Event>) { ... } fn notify_observers( &mut self, event: Event, ) -> impl Future<Output = ()> + Send { ... } fn try_notify_observers(&mut self, event: Event) { ... } }
Available on crate feature observer only.
Expand description

Describes the behavior of an actor which works as a subject of the given event type.

An actor could be the subject of multiple event types, just implement this trait multiple times.

Required Methods§

Source

fn observers_mut(&mut self) -> &mut ObserverSet<Event>

Returns a mutable reference to the set of observers for this event type.

Provided Methods§

Source

fn register_observer(&mut self, observer: Recipient<Event>)

Registers an observer.

Source

fn unregister_observer(&mut self, observer: Recipient<Event>)

Unregisters an observer.

Source

fn notify_observers(&mut self, event: Event) -> impl Future<Output = ()> + Send

Notifies all observers.

This method will wait until there is capacity in the mailbox of the observer.

Source

fn try_notify_observers(&mut self, event: Event)

Notifies all observers.

This method will return immediately if there is no capacity in the mailbox of the observer.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§