Trait Observable

Source
pub trait Observable<X, T: Subscription<X>> {
    // Required methods
    fn add_observer(&mut self, observer: Arc<T>);
    fn delete_observer(&mut self, observer: Arc<T>);
    fn notify_observers(&mut self, x: Arc<X>);
}
Expand description

Observable memorizes all Subscription and send notifications.

§Arguments

  • X - The generic type of broadcasted data
  • T - The generic type implementing trait Subscription

§Remarks

This is an implementation of Observer Pattern of GoF.

NOTE: Inspired by and modified from https://github.com/eliovir/rust-examples/blob/master/design_pattern-observer.rs

Required Methods§

Source

fn add_observer(&mut self, observer: Arc<T>)

Add a Subscription.

§Arguments
  • observer - The given Subscription.
Source

fn delete_observer(&mut self, observer: Arc<T>)

Remove the observer.

§Arguments
  • observer - The given Subscription.
Source

fn notify_observers(&mut self, x: Arc<X>)

Notify all Subscription subscribers with a given value Arc<X>.

§Arguments
  • x - The given Arc<X> value for broadcasting.

Implementors§

Source§

impl<X: Send + Sync + 'static> Observable<X, SubscriptionFunc<X>> for Publisher<X>