renamed trait

This commit is contained in:
Ulrich Mohr 2023-12-12 11:03:24 +01:00
parent e585ecafcc
commit 881ae8c096
2 changed files with 11 additions and 11 deletions

View File

@ -7,11 +7,11 @@ pub struct TypeId {
} }
// inspired by https://github.com/jswrenn/deflect/ // inspired by https://github.com/jswrenn/deflect/
pub trait Reflection { pub trait HasTypeId {
#[inline(never)] #[inline(never)]
fn get_type_id(&self) -> TypeId { fn get_type_id(&self) -> TypeId {
TypeId { TypeId {
id: <Self as Reflection>::get_type_id as usize, id: Self::get_type_id as usize,
} }
} }
} }
@ -24,27 +24,27 @@ pub trait DatapoolOwnerIF {
pub trait DataSetIF { pub trait DataSetIF {
fn get_type_id(&self) -> TypeId; fn get_type_id(&self) -> TypeId;
fn get_actual_data(&self) -> &dyn Reflection; fn get_actual_data(&self) -> &dyn HasTypeId;
fn get_mutex(&self) -> mutex::RawMutex; fn get_mutex(&self) -> mutex::RawMutex;
} }
pub struct OwnedDataset<T: Reflection + Copy> { pub struct OwnedDataset<T: HasTypeId + Copy> {
actual_data: T, actual_data: T,
mutex: mutex::RawMutex, mutex: mutex::RawMutex,
} }
pub struct ReferencedDataset<T: Reflection + Copy> { pub struct ReferencedDataset<T: HasTypeId + Copy> {
//we use a pointer here to avoid lifetimes //we use a pointer here to avoid lifetimes
actual_data: Option<*const T>, actual_data: Option<*const T>,
mutex: Option<mutex::RawMutex>, mutex: Option<mutex::RawMutex>,
} }
impl<T: Reflection + Copy> DataSetIF for OwnedDataset<T> { impl<T: HasTypeId + Copy> DataSetIF for OwnedDataset<T> {
fn get_type_id(&self) -> TypeId { fn get_type_id(&self) -> TypeId {
self.actual_data.get_type_id() self.actual_data.get_type_id()
} }
fn get_actual_data(&self) -> &dyn Reflection { fn get_actual_data(&self) -> &dyn HasTypeId {
&self.actual_data &self.actual_data
} }
@ -53,7 +53,7 @@ impl<T: Reflection + Copy> DataSetIF for OwnedDataset<T> {
} }
} }
impl<T: Reflection + Copy + Default> OwnedDataset<T> { impl<T: HasTypeId + Copy + Default> OwnedDataset<T> {
pub fn new() -> OwnedDataset<T> { pub fn new() -> OwnedDataset<T> {
OwnedDataset::<T> { OwnedDataset::<T> {
actual_data: T::default(), actual_data: T::default(),
@ -79,7 +79,7 @@ impl<T: Reflection + Copy + Default> OwnedDataset<T> {
} }
} }
impl<T: Reflection + Copy + Default> ReferencedDataset<T> { impl<T: HasTypeId + Copy + Default> ReferencedDataset<T> {
pub fn new() -> ReferencedDataset<T> { pub fn new() -> ReferencedDataset<T> {
ReferencedDataset::<T> { ReferencedDataset::<T> {
actual_data: None, actual_data: None,
@ -115,7 +115,7 @@ impl<T: Reflection + Copy + Default> ReferencedDataset<T> {
} }
//pointer cast is safe because we checked the type_id //pointer cast is safe because we checked the type_id
//getting pointer to avoid lifetime check //getting pointer to avoid lifetime check
self.actual_data = Some(other_set.get_actual_data() as *const dyn Reflection as *const T); self.actual_data = Some(other_set.get_actual_data() as *const dyn HasTypeId as *const T);
self.mutex = Some(other_set.get_mutex()); self.mutex = Some(other_set.get_mutex());
Ok(()) Ok(())
} }

View File

@ -56,7 +56,7 @@ struct HandlerData {
y: f32 y: f32
} }
impl datasets::Reflection for HandlerData {} impl datasets::HasTypeId for HandlerData {}
struct Handler { struct Handler {
id: objectmanager::ObjectId, id: objectmanager::ObjectId,