use std::{ops::Deref, sync::Arc}; pub struct BoxCallback(Box); impl BoxCallback { pub fn new(f: F) -> Self where F: Fn() + Send + Sync + 'static, { Self(Box::new(f)) } } impl Deref for BoxCallback { type Target = Box; fn deref(&self) -> &Self::Target { &self.0 } } impl From for BoxCallback where F: Fn() + Send + Sync + 'static, { fn from(value: F) -> Self { Self::new(value) } } pub struct BoxOneCallback(Box Return + Send + Sync + 'static>); impl BoxOneCallback { pub fn new(f: F) -> Self where F: Fn(A) -> Return + Send + Sync + 'static, { Self(Box::new(f)) } } impl Deref for BoxOneCallback { type Target = Box Return + Send + Sync + 'static>; fn deref(&self) -> &Self::Target { &self.0 } } impl From for BoxOneCallback where F: Fn(A) -> Return + Send + Sync + 'static, { fn from(value: F) -> Self { Self::new(value) } } #[derive(Clone)] pub struct ArcCallback(Arc); impl ArcCallback { pub fn new(f: F) -> Self where F: Fn() + Send + Sync + 'static, { Self(Arc::new(f)) } } impl Deref for ArcCallback { type Target = Arc; fn deref(&self) -> &Self::Target { &self.0 } } impl From for ArcCallback where F: Fn() + Send + Sync + 'static, { fn from(value: F) -> Self { Self::new(value) } } #[derive(Clone)] pub struct ArcOneCallback(Arc); impl ArcOneCallback { pub fn new(f: F) -> Self where F: Fn(A) + Send + Sync + 'static, { Self(Arc::new(f)) } } impl Deref for ArcOneCallback { type Target = Arc; fn deref(&self) -> &Self::Target { &self.0 } } impl From for ArcOneCallback where F: Fn(A) + Send + Sync + 'static, { fn from(value: F) -> Self { Self::new(value) } }