Trait fp_rust::common::Observable[][src]

pub trait Observable<X, T: Subscription<X>> {
    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

Add a Subscription.

Arguments

  • observer - The given Subscription.

Remove the observer.

Arguments

  • observer - The given Subscription.

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

Arguments

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

Implementors