chore: wipe away old src

This commit is contained in:
Jonathan Kelley committed 2022-11-20 15:58:05 -08:00
1 parent 493591400f
commit d407035931
29 files changed
+187 -6819

No files matched your search

+26 -9
View File
@@ -7,20 +7,33 @@ use crate::{
Element,
};
pub trait AnyProps<'a> {
fn as_ptr(&self) -> *const ();
/// A trait that essentially allows VComponentProps to be used generically
pub unsafe trait AnyProps<'a> {
fn props_ptr(&self) -> *const ();
fn render(&'a self, bump: &'a ScopeState) -> RenderReturn<'a>;
unsafe fn memoize(&self, other: &dyn AnyProps) -> bool;
}
pub(crate) struct VComponentProps<'a, P, A, F: ComponentReturn<'a, A> = Element<'a>> {
pub(crate) struct VProps<'a, P, A, F: ComponentReturn<'a, A> = Element<'a>> {
pub render_fn: fn(Scope<'a, P>) -> F,
pub memo: unsafe fn(&P, &P) -> bool,
pub props: P,
pub _marker: PhantomData<A>,
// pub props: PropsAllocation<P>,
_marker: PhantomData<A>,
}
impl<'a, P, A, F: ComponentReturn<'a, A>> VComponentProps<'a, P, A, F> {
enum PropsAllocation<P> {
/// If it's memoized, then the heap owns the props
Memoized(*mut P),
/// If it's borrowed, then the parent owns the props
Borrowed(P),
}
impl<'a, P, A, F> VProps<'a, P, A, F>
where
F: ComponentReturn<'a, A>,
{
pub(crate) fn new(
render_fn: fn(Scope<'a, P>) -> F,
memo: unsafe fn(&P, &P) -> bool,
@@ -30,13 +43,17 @@ impl<'a, P, A, F: ComponentReturn<'a, A>> VComponentProps<'a, P, A, F> {
render_fn,
memo,
props,
// props: PropsAllocation::Borrowed(props),
_marker: PhantomData,
}
}
}
impl<'a, P, A, F: ComponentReturn<'a, A>> AnyProps<'a> for VComponentProps<'a, P, A, F> {
fn as_ptr(&self) -> *const () {
unsafe impl<'a, P, A, F> AnyProps<'a> for VProps<'a, P, A, F>
where
F: ComponentReturn<'a, A>,
{
fn props_ptr(&self) -> *const () {
&self.props as *const _ as *const ()
}
@@ -45,8 +62,8 @@ impl<'a, P, A, F: ComponentReturn<'a, A>> AnyProps<'a> for VComponentProps<'a, P
// you *must* make this check *before* calling this method
// if your functions are not the same, then you will downcast a pointer into a different type (UB)
unsafe fn memoize(&self, other: &dyn AnyProps) -> bool {
let real_other: &P = &*(other.as_ptr() as *const _ as *const P);
let real_us: &P = &*(self.as_ptr() as *const _ as *const P);
let real_other: &P = &*(other.props_ptr() as *const _ as *const P);
let real_us: &P = &*(self.props_ptr() as *const _ as *const P);
(self.memo)(real_us, real_other)
}