Evan Almloff пре 2 година
родитељ
комит
2c205f8ca5

+ 13 - 13
packages/native-core/src/passes.rs

@@ -109,7 +109,7 @@ impl DirtyNodeStates {
     }
 }
 
-pub trait Pass<V: FromAnyValue + Send = ()>: Any {
+pub trait Pass<V: FromAnyValue + Send + Sync = ()>: Any + Send + Sync {
     /// This is a tuple of (T: Any, ..)
     type ParentDependencies: Dependancy;
     /// This is a tuple of (T: Any, ..)
@@ -299,17 +299,17 @@ pub enum PassDirection {
 type PassCallback = Box<dyn Fn(NodeId, &mut TreeStateView, &SendAnyMap) -> bool + Send + Sync>;
 
 pub trait AnyMapLike<'a> {
-    fn get<T: Any>(self) -> Option<&'a T>;
+    fn get<T: Any + Sync + Send>(self) -> Option<&'a T>;
 }
 
 impl<'a> AnyMapLike<'a> for &'a AnyMap {
-    fn get<T: Any>(self) -> Option<&'a T> {
+    fn get<T: Any + Sync + Send>(self) -> Option<&'a T> {
         self.get()
     }
 }
 
 impl<'a> AnyMapLike<'a> for &'a SendAnyMap {
-    fn get<T: Any>(self) -> Option<&'a T> {
+    fn get<T: Any + Sync + Send>(self) -> Option<&'a T> {
         todo!()
     }
 }
@@ -327,7 +327,7 @@ pub trait Dependancy {
 
 macro_rules! impl_dependancy {
     ($($t:ident),*) => {
-        impl< $($t: Any),* > Dependancy for ($($t,)*) {
+        impl< $($t: Any + Send + Sync),* > Dependancy for ($($t,)*) {
             type ElementBorrowed<'a> = ($(&'a $t,)*) where Self: 'a;
 
             #[allow(unused_variables, clippy::unused_unit, non_snake_case)]
@@ -423,7 +423,7 @@ pub fn resolve_passes<V: FromAnyValue + Send + Sync>(
 //     }
 
 //     impl AnyMapLike for Number {
-//         fn get<T: Any>(&self) -> Option<&T> {
+//         fn get<T: Any+Sync+Send>(&self) -> Option<&T> {
 //             if TypeId::of::<Self>() == TypeId::of::<T>() {
 //                 Some(unsafe { &*(self as *const Self as *const T) })
 //             } else {
@@ -431,7 +431,7 @@ pub fn resolve_passes<V: FromAnyValue + Send + Sync>(
 //             }
 //         }
 
-//         fn get_mut<T: Any>(&mut self) -> Option<&mut T> {
+//         fn get_mut<T: Any+Sync+Send>(&mut self) -> Option<&mut T> {
 //             if TypeId::of::<Self>() == TypeId::of::<T>() {
 //                 Some(unsafe { &mut *(self as *mut Self as *mut T) })
 //             } else {
@@ -530,7 +530,7 @@ pub fn resolve_passes<V: FromAnyValue + Send + Sync>(
 //     }
 
 //     impl AnyMapLike for NumberState {
-//         fn get<T: Any>(&self) -> Option<&T> {
+//         fn get<T: Any+Sync+Send>(&self) -> Option<&T> {
 //             if TypeId::of::<AddNumber>() == TypeId::of::<T>() {
 //                 Some(unsafe { &*(&self.add_number as *const AddNumber as *const T) })
 //             } else if TypeId::of::<SubtractNumber>() == TypeId::of::<T>() {
@@ -540,7 +540,7 @@ pub fn resolve_passes<V: FromAnyValue + Send + Sync>(
 //             }
 //         }
 
-//         fn get_mut<T: Any>(&mut self) -> Option<&mut T> {
+//         fn get_mut<T: Any+Sync+Send>(&mut self) -> Option<&mut T> {
 //             if TypeId::of::<AddNumber>() == TypeId::of::<T>() {
 //                 Some(unsafe { &mut *(&mut self.add_number as *mut AddNumber as *mut T) })
 //             } else if TypeId::of::<SubtractNumber>() == TypeId::of::<T>() {
@@ -636,7 +636,7 @@ pub fn resolve_passes<V: FromAnyValue + Send + Sync>(
 //     }
 
 //     impl AnyMapLike for NumberState {
-//         fn get<T: Any>(&self) -> Option<&T> {
+//         fn get<T: Any+Sync+Send>(&self) -> Option<&T> {
 //             if TypeId::of::<AddNumber>() == TypeId::of::<T>() {
 //                 Some(unsafe { &*(&self.add_number as *const AddNumber as *const T) })
 //             } else if TypeId::of::<SubtractNumber>() == TypeId::of::<T>() {
@@ -646,7 +646,7 @@ pub fn resolve_passes<V: FromAnyValue + Send + Sync>(
 //             }
 //         }
 
-//         fn get_mut<T: Any>(&mut self) -> Option<&mut T> {
+//         fn get_mut<T: Any+Sync+Send>(&mut self) -> Option<&mut T> {
 //             if TypeId::of::<AddNumber>() == TypeId::of::<T>() {
 //                 Some(unsafe { &mut *(&mut self.add_number as *mut AddNumber as *mut T) })
 //             } else if TypeId::of::<SubtractNumber>() == TypeId::of::<T>() {
@@ -718,7 +718,7 @@ pub fn resolve_passes<V: FromAnyValue + Send + Sync>(
 //     }
 
 //     impl AnyMapLike for NumberState {
-//         fn get<T: Any>(&self) -> Option<&T> {
+//         fn get<T: Any+Sync+Send>(&self) -> Option<&T> {
 //             if TypeId::of::<AddNumber>() == TypeId::of::<T>() {
 //                 Some(unsafe { &*(&self.add_number as *const AddNumber as *const T) })
 //             } else {
@@ -726,7 +726,7 @@ pub fn resolve_passes<V: FromAnyValue + Send + Sync>(
 //             }
 //         }
 
-//         fn get_mut<T: Any>(&mut self) -> Option<&mut T> {
+//         fn get_mut<T: Any+Sync+Send>(&mut self) -> Option<&mut T> {
 //             if TypeId::of::<AddNumber>() == TypeId::of::<T>() {
 //                 Some(unsafe { &mut *(&mut self.add_number as *mut AddNumber as *mut T) })
 //             } else {

+ 5 - 4
packages/native-core/src/real_dom.rs

@@ -37,6 +37,7 @@ pub struct RealDom<V: FromAnyValue + Send + Sync = ()> {
 impl<V: FromAnyValue + Send + Sync> RealDom<V> {
     pub fn new(mut passes: Box<[TypeErasedPass<V>]>) -> RealDom<V> {
         let mut tree = Tree::new();
+        tree.insert_slab::<NodeData<V>>();
         let root_id = tree.root();
         let root: &mut NodeData<V> = tree.get_mut(root_id).unwrap();
         let mut root_node: NodeData<V> = NodeData::new(NodeType::Element(ElementNode {
@@ -579,7 +580,7 @@ pub trait NodeImmutable<V: FromAnyValue + Send + Sync>: Sized {
         &self.node_data().node_type
     }
 
-    fn get<T: Any>(&self) -> Option<&T> {
+    fn get<T: Any + Sync + Send>(&self) -> Option<&T> {
         self.real_dom().tree.get(self.id())
     }
 
@@ -611,7 +612,7 @@ pub trait NodeImmutable<V: FromAnyValue + Send + Sync>: Sized {
 }
 
 pub trait NodeMutable<V: FromAnyValue + Send + Sync>: Sized + NodeImmutable<V> {
-    fn get_mut<T: Any>(&mut self) -> Option<&mut T>;
+    fn get_mut<T: Any + Sync + Send>(&mut self) -> Option<&mut T>;
 }
 
 #[derive(Clone, Copy)]
@@ -647,7 +648,7 @@ impl<'a, V: FromAnyValue + Send + Sync> NodeImmutable<V> for NodeMut<'a, V> {
 }
 
 impl<'a, V: FromAnyValue + Send + Sync> NodeMutable<V> for NodeMut<'a, V> {
-    fn get_mut<T: Any>(&mut self) -> Option<&mut T> {
+    fn get_mut<T: Any + Sync + Send>(&mut self) -> Option<&mut T> {
         todo!("get_mut with mark as dirty")
     }
 }
@@ -781,7 +782,7 @@ impl<'a, V: FromAnyValue + Send + Sync> NodeImmutable<V> for NodeMutRaw<'a, V> {
 }
 
 impl<'a, V: FromAnyValue + Send + Sync> NodeMutable<V> for NodeMutRaw<'a, V> {
-    fn get_mut<T: Any>(&mut self) -> Option<&mut T> {
+    fn get_mut<T: Any + Sync + Send>(&mut self) -> Option<&mut T> {
         self.dom.tree.get_mut::<T>(self.id)
     }
 }

+ 17 - 13
packages/native-core/src/tree.rs

@@ -36,6 +36,10 @@ impl Tree {
         Self { nodes, root }
     }
 
+    pub(crate) fn insert_slab<T: Any + Send + Sync>(&mut self) {
+        self.nodes.get_or_insert_slab_mut::<T>();
+    }
+
     fn node_slab(&self) -> &SlabStorage<Node> {
         self.nodes.read_slab()
     }
@@ -164,11 +168,11 @@ impl Tree {
         }
     }
 
-    pub fn get<T: Any>(&self, id: NodeId) -> Option<&T> {
+    pub fn get<T: Any + Sync + Send>(&self, id: NodeId) -> Option<&T> {
         self.nodes.read_slab().get(id)
     }
 
-    pub fn get_mut<T: Any>(&mut self, id: NodeId) -> Option<&mut T> {
+    pub fn get_mut<T: Any + Sync + Send>(&mut self, id: NodeId) -> Option<&mut T> {
         self.nodes.write_slab().get_mut(id)
     }
 
@@ -234,7 +238,7 @@ pub struct TreeStateViewEntry<'a, 'b> {
 }
 
 impl<'a, 'b> AnyMapLike<'a> for TreeStateViewEntry<'a, 'b> {
-    fn get<T: Any>(self) -> Option<&'a T> {
+    fn get<T: Any + Sync + Send>(self) -> Option<&'a T> {
         self.view.get_slab().and_then(|slab| slab.get(self.id))
     }
 }
@@ -245,7 +249,7 @@ pub struct TreeStateView<'a, 'b> {
 }
 
 impl<'a, 'b> TreeStateView<'a, 'b> {
-    fn get_slab<T: Any>(&self) -> Option<&SlabStorage<T>> {
+    fn get_slab<T: Any + Sync + Send>(&self) -> Option<&SlabStorage<T>> {
         self.nodes
             .get(&TypeId::of::<T>())
             .and_then(|gaurd| match gaurd {
@@ -254,7 +258,7 @@ impl<'a, 'b> TreeStateView<'a, 'b> {
             })
     }
 
-    fn get_slab_mut<T: Any>(&mut self) -> Option<&mut SlabStorage<T>> {
+    fn get_slab_mut<T: Any + Sync + Send>(&mut self) -> Option<&mut SlabStorage<T>> {
         self.nodes
             .get_mut(&TypeId::of::<T>())
             .and_then(|gaurd| match gaurd {
@@ -279,11 +283,11 @@ impl<'a, 'b> TreeStateView<'a, 'b> {
         T::borrow_elements_from(self.entry(id))
     }
 
-    pub fn get_single<T: Any>(&self, id: NodeId) -> Option<&T> {
+    pub fn get_single<T: Any + Sync + Send>(&self, id: NodeId) -> Option<&T> {
         self.get_slab().and_then(|slab| slab.get(id))
     }
 
-    pub fn get_mut<T: Any>(&mut self, id: NodeId) -> Option<&mut T> {
+    pub fn get_mut<T: Any + Sync + Send>(&mut self, id: NodeId) -> Option<&mut T> {
         self.get_slab_mut().and_then(|slab| slab.get_mut(id))
     }
 
@@ -543,23 +547,23 @@ impl AnySlab {
         }
     }
 
-    fn try_read_slab<T: Any>(&self) -> Option<&SlabStorage<T>> {
+    fn try_read_slab<T: Any + Sync + Send>(&self) -> Option<&SlabStorage<T>> {
         self.data
             .get(&TypeId::of::<T>())
             .map(|x| x.as_any().downcast_ref().unwrap())
     }
 
-    fn read_slab<T: Any>(&self) -> &SlabStorage<T> {
+    fn read_slab<T: Any + Sync + Send>(&self) -> &SlabStorage<T> {
         self.try_read_slab().unwrap()
     }
 
-    fn try_write_slab<T: Any>(&mut self) -> Option<&mut SlabStorage<T>> {
+    fn try_write_slab<T: Any + Sync + Send>(&mut self) -> Option<&mut SlabStorage<T>> {
         self.data
             .get_mut(&TypeId::of::<T>())
             .map(|x| x.as_any_mut().downcast_mut().unwrap())
     }
 
-    fn write_slab<T: Any>(&mut self) -> &mut SlabStorage<T> {
+    fn write_slab<T: Any + Sync + Send>(&mut self) -> &mut SlabStorage<T> {
         self.try_write_slab().unwrap()
     }
 
@@ -624,11 +628,11 @@ impl EntryBuilder<'_> {
             .insert(self.id, value);
     }
 
-    pub fn get<T: Any>(&self) -> Option<&T> {
+    pub fn get<T: Any + Sync + Send>(&self) -> Option<&T> {
         self.inner.read_slab().get(self.id)
     }
 
-    pub fn get_mut<T: Any>(&mut self) -> Option<&mut T> {
+    pub fn get_mut<T: Any + Sync + Send>(&mut self) -> Option<&mut T> {
         self.inner.write_slab().get_mut(self.id)
     }