use std::any::Any;
pub trait CloneableAny: CloneableImpl {}
pub trait CloneableImpl {
fn clone_box(&self) -> Box<dyn CloneableAny>;
fn as_any(&self) -> &dyn Any;
}
impl<T> CloneableImpl for T
where
T: 'static + CloneableAny + Clone,
{
fn clone_box(&self) -> Box<dyn CloneableAny> {
Box::new(self.clone())
}
fn as_any(&self) -> &dyn Any {
self
}
}
impl Clone for Box<dyn CloneableAny> {
fn clone(&self) -> Box<dyn CloneableAny> {
self.clone_box()
}
}
impl<T: 'static + Clone> CloneableAny for Vec<T> {}