generalize Layers

This commit is contained in:
🪞👃🪞 2024-09-15 19:53:20 +03:00
parent 35b37e3e3a
commit f7b2134310
3 changed files with 53 additions and 33 deletions

View file

@ -12,8 +12,8 @@ pub trait Engine: Send + Sync + Sized {
type Output: Output<Self>;
type Unit: Number;
type Area: Area<Self::Unit> + From<[Self::Unit;4]> + Debug;
type Size: Size<Self::Unit> + From<[Self::Unit;2]> + Debug;
type Area: Area<Self::Unit> + From<[Self::Unit;4]> + Debug + Copy;
type Size: Size<Self::Unit> + From<[Self::Unit;2]> + Debug + Copy;
fn setup (&mut self) -> Usually<()> { Ok(()) }
fn exited (&self) -> bool;
@ -163,13 +163,11 @@ impl<E: Engine, C: Component<E> + Exit> ExitableComponent<E> for C {}
pub trait Handle<E: Engine>: Send + Sync {
fn handle (&mut self, context: &E::Input) -> Perhaps<E::Handled>;
}
impl<H, E: Engine> Handle<E> for &mut H where H: Handle<E> {
fn handle (&mut self, context: &E::Input) -> Perhaps<E::Handled> {
(*self).handle(context)
}
}
impl<H, E: Engine> Handle<E> for Option<H> where H: Handle<E> {
fn handle (&mut self, context: &E::Input) -> Perhaps<E::Handled> {
if let Some(ref mut handle) = self {
@ -179,25 +177,21 @@ impl<H, E: Engine> Handle<E> for Option<H> where H: Handle<E> {
}
}
}
impl<H, E: Engine> Handle<E> for Mutex<H> where H: Handle<E> {
fn handle (&mut self, context: &E::Input) -> Perhaps<E::Handled> {
self.lock().unwrap().handle(context)
}
}
impl<H, E: Engine> Handle<E> for Arc<Mutex<H>> where H: Handle<E> {
fn handle (&mut self, context: &E::Input) -> Perhaps<E::Handled> {
self.lock().unwrap().handle(context)
}
}
impl<H, E: Engine> Handle<E> for RwLock<H> where H: Handle<E> {
fn handle (&mut self, context: &E::Input) -> Perhaps<E::Handled> {
self.write().unwrap().handle(context)
}
}
impl<H, E: Engine> Handle<E> for Arc<RwLock<H>> where H: Handle<E> {
fn handle (&mut self, context: &E::Input) -> Perhaps<E::Handled> {
self.write().unwrap().handle(context)