1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
use super::traits::*; use std::sync::*; struct NotifyFn<TFn> { when_changed: Mutex<TFn> } impl<TFn> Notifiable for NotifyFn<TFn> where TFn: Send+FnMut() -> () { fn mark_as_changed(&self) { let on_changed = &mut *self.when_changed.lock().unwrap(); on_changed() } } /// /// Creates a notifiable reference from a function /// pub fn notify<TFn>(when_changed: TFn) -> Arc<dyn Notifiable> where TFn: 'static+Send+FnMut() -> () { Arc::new(NotifyFn { when_changed: Mutex::new(when_changed) }) }