try specialization

This commit is contained in:
Evan Almloff 2023-10-26 16:36:41 -05:00
parent 1126c1d329
commit 4ac6aed482
2 changed files with 45 additions and 1 deletions

View file

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

View file

@ -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> {}