forked from ROMEO/obsw
renamed trait
This commit is contained in:
parent
e585ecafcc
commit
881ae8c096
@ -7,11 +7,11 @@ pub struct TypeId {
|
||||
}
|
||||
|
||||
// inspired by https://github.com/jswrenn/deflect/
|
||||
pub trait Reflection {
|
||||
pub trait HasTypeId {
|
||||
#[inline(never)]
|
||||
fn get_type_id(&self) -> 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 {
|
||||
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;
|
||||
}
|
||||
|
||||
pub struct OwnedDataset<T: Reflection + Copy> {
|
||||
pub struct OwnedDataset<T: HasTypeId + Copy> {
|
||||
actual_data: T,
|
||||
mutex: mutex::RawMutex,
|
||||
}
|
||||
|
||||
pub struct ReferencedDataset<T: Reflection + Copy> {
|
||||
pub struct ReferencedDataset<T: HasTypeId + Copy> {
|
||||
//we use a pointer here to avoid lifetimes
|
||||
actual_data: Option<*const T>,
|
||||
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 {
|
||||
self.actual_data.get_type_id()
|
||||
}
|
||||
|
||||
fn get_actual_data(&self) -> &dyn Reflection {
|
||||
fn get_actual_data(&self) -> &dyn HasTypeId {
|
||||
&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> {
|
||||
OwnedDataset::<T> {
|
||||
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> {
|
||||
ReferencedDataset::<T> {
|
||||
actual_data: None,
|
||||
@ -115,7 +115,7 @@ impl<T: Reflection + Copy + Default> ReferencedDataset<T> {
|
||||
}
|
||||
//pointer cast is safe because we checked the type_id
|
||||
//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());
|
||||
Ok(())
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ struct HandlerData {
|
||||
y: f32
|
||||
}
|
||||
|
||||
impl datasets::Reflection for HandlerData {}
|
||||
impl datasets::HasTypeId for HandlerData {}
|
||||
|
||||
struct Handler {
|
||||
id: objectmanager::ObjectId,
|
||||
|
Loading…
x
Reference in New Issue
Block a user