Forever: Simplify pointer handling

This commit is contained in:
Grant Miller 2022-07-25 23:09:07 -05:00
parent 41e392bda3
commit 1d63a30d5f

View File

@ -74,12 +74,8 @@ impl<T> Forever<T> {
panic!("Forever.put() called multiple times"); panic!("Forever.put() called multiple times");
} }
unsafe { let p: &'static mut MaybeUninit<T> = unsafe { &mut *self.t.get() };
let p = self.t.get(); p.write(val())
let p = (&mut *p).as_mut_ptr();
p.write(val());
&mut *p
}
} }
/// Unsafely get a mutable reference to the contents of this Forever. /// Unsafely get a mutable reference to the contents of this Forever.
@ -93,8 +89,7 @@ impl<T> Forever<T> {
#[inline(always)] #[inline(always)]
#[allow(clippy::mut_from_ref)] #[allow(clippy::mut_from_ref)]
pub unsafe fn steal(&self) -> &mut T { pub unsafe fn steal(&self) -> &mut T {
let p = self.t.get(); let p: &mut MaybeUninit<T> = &mut *self.t.get();
let p = (&mut *p).as_mut_ptr(); p.assume_init_mut()
&mut *p
} }
} }