reflect: implement TypeData for T

This commit is contained in:
SeanOMik 2024-01-04 20:43:46 -05:00
parent 67c5876443
commit 74f43e9ffe
Signed by: SeanOMik
GPG Key ID: FEC9E2FC15235964
1 changed files with 14 additions and 0 deletions

View File

@ -45,6 +45,20 @@ pub trait TypeData: std::any::Any {
fn boxed_clone(&self) -> Box<dyn TypeData>;
}
impl<T: Clone + 'static> TypeData for T {
fn as_any(&self) -> &dyn std::any::Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
self
}
fn boxed_clone(&self) -> Box<dyn TypeData> {
Box::new(self.clone())
}
}
#[derive(Default)]
pub struct RegisteredType {
data: HashMap<TypeId, Box<dyn TypeData>>,