Use Forever::put_with inside Forever::put

This commit is contained in:
Grant Miller 2022-07-25 22:30:01 -05:00
parent 84cffc751a
commit 41e392bda3

View File

@ -52,20 +52,7 @@ impl<T> Forever<T> {
#[inline(always)] #[inline(always)]
#[allow(clippy::mut_from_ref)] #[allow(clippy::mut_from_ref)]
pub fn put(&'static self, val: T) -> &'static mut T { pub fn put(&'static self, val: T) -> &'static mut T {
if self self.put_with(|| val)
.used
.compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed)
.is_err()
{
panic!("Forever::put() called multiple times");
}
unsafe {
let p = self.t.get();
let p = (&mut *p).as_mut_ptr();
p.write(val);
&mut *p
}
} }
/// Store the closure return value in this `Forever`, returning a mutable reference to it. /// Store the closure return value in this `Forever`, returning a mutable reference to it.