pub struct ObserverNumberProducer {
    number: u32,
    observers: Vec<Rc<RefCell<dyn IObserverNumberChanged>>>,
}
Expand description

Represents the Observer Subject in this example, in this case, a struct that contains a single number that is updated with a call to the update() method. Whenever update() is called, the number is incremented and all observers are notified. The observers are passed (“pushed”) the changed number through the IObserverNumberChanged trait.

Fields§

§number: u32

The number being maintained.

§observers: Vec<Rc<RefCell<dyn IObserverNumberChanged>>>

The list of observers subscribed to this class instance.

Implementations§

source§

impl ObserverNumberProducer

source

pub fn new() -> ObserverNumberProducer

Default constructor

source

pub fn add_observer( &mut self, observer: &Rc<RefCell<dyn IObserverNumberChanged>> )

Call this method to subscribe an observer to this struct for notifications about changing numbers. Does nothing if the given observer is already subscribed.

Parameters
  • observer

    The observer as represented by the IObserverNumberChanged trait.

source

pub fn remove_observer( &mut self, observer: &Rc<RefCell<dyn IObserverNumberChanged>> )

Call this method to unsubscribe an observer from this struct so notifications are no longer received. Does nothing if the given observer was not subscribed.

Parameters
  • observer

    The observer as represented by the IObserverNumberChanged trait.

source

pub fn update(&mut self)

Update the number then notify all observers.

source

fn find_index_of_observer( &self, observer: &Rc<RefCell<dyn IObserverNumberChanged>> ) -> Option<usize>

Helper method to retrieve the index to the specified observer if the observer is in the list.

Parameters
  • observer

    The observer as represented by the IObserverNumberChanged trait.

Returns

Returns Some(index) if the observer was found; otherwise, returns None.

source

fn notify_observers(&self)

Helper method to notify all observers that the number has changed.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

source§

fn vzip(self) -> V