Pārlūkot izejas kodu

try specialization

Evan Almloff 1 gadu atpakaļ
vecāks
revīzija
4ac6aed482

+ 1 - 1
packages/generational-box/src/lib.rs

@@ -12,7 +12,7 @@ use std::{
     sync::{atomic::AtomicU32, Arc},
 };
 
-use bumpalo::Bump;
+mod testing;
 
 /// # Example
 ///

+ 44 - 0
packages/generational-box/src/testing.rs

@@ -0,0 +1,44 @@
+use core::marker::PhantomData;
+
+#[test]
+fn testing() {
+    let testing1 = Testing::<_, false>::new(&() as *const _);
+    // std::thread::spawn(move || testing1);
+}
+
+struct Testing<T, const SYNC: bool> {
+    ptr: *mut (),
+    phantom: PhantomData<T>,
+}
+
+trait CreateNew<T> {
+    fn new(data: T) -> Testing<T, true> {
+        Testing {
+            ptr: &mut (),
+            phantom: PhantomData,
+        }
+    }
+}
+
+impl<T> CreateNew<T> for Testing<T, false> {
+    fn new(data: T) -> Testing<T, true> {
+        Testing {
+            ptr: &mut (),
+            phantom: PhantomData,
+        }
+    }
+}
+
+impl<T: Sync + Send + 'static> Testing<T, true> {
+    pub fn new(data: T) -> Self {
+        Testing {
+            ptr: &mut (),
+            phantom: PhantomData,
+        }
+    }
+}
+
+impl<T: 'static> Testing<T, false> {}
+
+unsafe impl<T: Send + Sync + 'static> Send for Testing<T, true> {}
+unsafe impl<T: Send + Sync + 'static> Sync for Testing<T, true> {}