HeapJob drops Job and Self

This commit is contained in:
Janis 2025-02-21 20:05:02 +01:00
parent c25b62ee3e
commit 11514efd30

View file

@ -803,15 +803,22 @@ mod job {
#[allow(dead_code)]
pub struct HeapJob<F> {
f: F,
_phantom: PhantomPinned,
}
impl<F> HeapJob<F> {
#[allow(dead_code)]
pub fn new(f: F) -> Box<Self> {
Box::new(Self { f })
Box::new(Self {
f,
_phantom: PhantomPinned,
})
}
pub fn into_inner(self) -> F {
self.f
}
#[allow(dead_code)]
pub fn into_boxed_job<T>(self: Box<Self>) -> Box<Job<()>>
pub fn into_boxed_job<T>(self: Box<Self>) -> Pin<Box<Job<()>>>
where
F: FnOnce(&super::Scope) -> T + Send,
T: Send,
@ -824,13 +831,12 @@ mod job {
let this = unsafe { Box::from_raw(this.cast::<HeapJob<F>>().cast_mut()) };
let f = this.f;
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| f(scope)));
_ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| f(scope)));
let job = unsafe { &*job.cast::<Job<T>>() };
job.complete(result);
_ = unsafe { Box::from_raw(job.cast_mut()) };
}
Box::new(Job::new(harness::<F, T>, unsafe {
Box::pin(Job::new(harness::<F, T>, unsafe {
NonNull::new_unchecked(Box::into_raw(self)).cast()
}))
}