VecSubject

Struct VecSubject 

Source
pub struct VecSubject<O>
where O: Observer,
{ /* private fields */ }
Expand description

Implements Subject backed by a Vec<T>. If T implements Eq, then DetachableSubject is also provided. AttachableSubject is always provided.

§Examples

use roopes::prelude::*;
use std::{
   cell::RefCell,
   rc::Rc,
};

let mut vs = observer::VecSubject::default();

let has_run = Rc::new(RefCell::new(false));
{
   let has_run = has_run.clone();

   let lc: ObservingCommand<_> =
       command::Heap::from(move
|| {             (*has_run.borrow_mut()) =
true;         })
       .into();

   vs.attach(lc);
}

assert!(!(*has_run.borrow()));
vs.notify();
assert!((*has_run.borrow()));

Implementations§

Source§

impl<O> VecSubject<O>
where O: Observer,

Source

pub fn new(listeners: RefCell<Vec<O>>) -> VecSubject<O>

Creates a new VecSubject with an existing list of listeners. VecSubject::default is probably preferable in most circumstances.

Trait Implementations§

Source§

impl<O> AttachableSubject<O> for VecSubject<O>
where O: Observer,

Source§

fn attach(&mut self, attach_observer: O)

Adds the Observer to the list of elements notified when the Subject is notified.
Source§

impl<O> Default for VecSubject<O>
where O: Observer,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<O> DetachableSubject<O, DetachError> for VecSubject<O>
where O: Observer + Eq,

Source§

fn detach(&mut self, detach_observer: &O) -> Result<(), DetachError>

Detaches the given Observer from the Subject so it would no longer receive notifications. Read more
Source§

impl<O> Subject for VecSubject<O>
where O: Observer,

Source§

fn notify(&self)

Triggers the Observers corresponding notify implementations.

Auto Trait Implementations§

§

impl<O> !Freeze for VecSubject<O>

§

impl<O> !RefUnwindSafe for VecSubject<O>

§

impl<O> Send for VecSubject<O>
where O: Send,

§

impl<O> !Sync for VecSubject<O>

§

impl<O> Unpin for VecSubject<O>
where O: Unpin,

§

impl<O> UnwindSafe for VecSubject<O>
where O: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.