use crate::*; /// Current input state pub trait Input { /// Type of input event type Event; /// Currently handled event fn event (&self) -> &Self::Event; /// Whether component should exit fn is_done (&self) -> bool; /// Mark component as done fn done (&self); } /// Handle input pub trait Handle: Send + Sync { fn handle (&mut self, context: &E::Input) -> Perhaps; } impl> Handle for &mut H { fn handle (&mut self, context: &E::Input) -> Perhaps { (*self).handle(context) } } impl> Handle for Option { fn handle (&mut self, context: &E::Input) -> Perhaps { if let Some(ref mut handle) = self { handle.handle(context) } else { Ok(None) } } } impl Handle for Mutex where H: Handle { fn handle (&mut self, context: &E::Input) -> Perhaps { self.lock().unwrap().handle(context) } } impl Handle for Arc> where H: Handle { fn handle (&mut self, context: &E::Input) -> Perhaps { self.lock().unwrap().handle(context) } } impl Handle for RwLock where H: Handle { fn handle (&mut self, context: &E::Input) -> Perhaps { self.write().unwrap().handle(context) } } impl Handle for Arc> where H: Handle { fn handle (&mut self, context: &E::Input) -> Perhaps { self.write().unwrap().handle(context) } }