wip: foregin eq from comparapable comp type.
This commit adds the framework for "comparable components". This allows complete sealing of bump-allocated properties types, and a comparison method that performs a "safe" cast without transmute. This lets us completely erase types but still be able to perform partialeq over render frames
This commit is contained in:
1 parent
5ad81885e4
commit
ec801eab16
6 files changed
+94
-34
No files matched your search
@@ -7,13 +7,64 @@
|
||||
|
||||
use crate::innerlude::FC;
|
||||
|
||||
use self::sized_any::SizedAny;
|
||||
|
||||
pub type ScopeIdx = generational_arena::Index;
|
||||
|
||||
struct ComparableComp<'s> {
|
||||
fc_raw: *const (),
|
||||
f: &'s dyn SizedAny,
|
||||
}
|
||||
|
||||
impl<'s> ComparableComp<'s> {
|
||||
fn compare_to<P: Properties>(&self, other: &ComparableComp) -> bool {
|
||||
if self.fc_raw == other.fc_raw {
|
||||
let real_other = unsafe { &*(other.f as *const _ as *const P) };
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct TestProps {}
|
||||
|
||||
fn test() {}
|
||||
|
||||
mod sized_any {
|
||||
use std::any::TypeId;
|
||||
|
||||
// don't allow other implementations of `SizedAny`; `SizedAny` must only be
|
||||
// implemented for sized types.
|
||||
mod seal {
|
||||
// it must be a `pub trait`, but not be reachable - hide it in
|
||||
// private mod.
|
||||
pub trait Seal {}
|
||||
}
|
||||
|
||||
pub trait SizedAny: seal::Seal {}
|
||||
|
||||
impl<T> seal::Seal for T {}
|
||||
impl<T> SizedAny for T {}
|
||||
|
||||
// `SizedAny + ?Sized` means it can be a trait object, but `SizedAny` was
|
||||
// implemented for the underlying sized type.
|
||||
pub fn downcast_ref<From, To>(v: &From) -> Option<&To>
|
||||
where
|
||||
From: SizedAny + ?Sized + 'static,
|
||||
To: 'static,
|
||||
{
|
||||
// if TypeId::of::<To>() == < From as SizedAny>::get_type_id(v) {
|
||||
Some(unsafe { &*(v as *const From as *const To) })
|
||||
// } else {
|
||||
// None
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Properties: PartialEq {
|
||||
type Builder;
|
||||
type StaticOutput: Properties + 'static;
|
||||
fn builder() -> Self::Builder;
|
||||
unsafe fn into_static(self) -> Self::StaticOutput;
|
||||
}
|
||||
|
||||
pub struct EmptyBuilder;
|
||||
@@ -25,15 +76,10 @@ impl EmptyBuilder {
|
||||
|
||||
impl Properties for () {
|
||||
type Builder = EmptyBuilder;
|
||||
type StaticOutput = ();
|
||||
|
||||
fn builder() -> Self::Builder {
|
||||
EmptyBuilder {}
|
||||
}
|
||||
|
||||
unsafe fn into_static(self) -> Self::StaticOutput {
|
||||
std::mem::transmute(self)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fc_to_builder<T: Properties>(_f: FC<T>) -> T::Builder {
|
||||
|
||||
Reference in new issue
Block a user