HashSubject

Struct HashSubject 

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

Implements Subject backed by a HashSet<T>. T must implement PartialEq and Hash.

§Examples

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

let mut hs = observer::HashSubject::default();

let has_run = Rc::new(RefCell::new(false));
let lc: ObservingCommand<_> = command::Hashable::new(
    command::Heap::from(enclose!((has_run) move || {
        (*has_run.borrow_mut()) = true;
    })),
    "Has Run").into();

hs.attach(lc);

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

Implementations§

Source§

impl<O> HashSubject<O>
where O: HashSetObserver,

Source

pub fn new(listeners: HashSet<O>) -> HashSubject<O>

Creates a new HashSubject with an interior-mutable listener set. HashSubject::default is probably preferable in most situations.

Trait Implementations§

Source§

impl<O> AttachableSubject<O> for HashSubject<O>
where O: HashSetObserver,

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 HashSubject<O>
where O: HashSetObserver,

Source§

fn default() -> HashSubject<O>

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

impl<O> DetachableSubject<O, DetachError> for HashSubject<O>
where O: HashSetObserver,

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 HashSubject<O>
where O: HashSetObserver,

Source§

fn notify(&self)

Triggers the Observers corresponding notify implementations.

Auto Trait Implementations§

§

impl<O> Freeze for HashSubject<O>

§

impl<O> RefUnwindSafe for HashSubject<O>
where O: RefUnwindSafe,

§

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

§

impl<O> Sync for HashSubject<O>
where O: Sync,

§

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

§

impl<O> UnwindSafe for HashSubject<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.