replace_with icon indicating copy to clipboard operation
replace_with copied to clipboard

Use `#[cfg(panic = "abort")]` to make `replace_with_or_abort_unchecked` safe

Open sentinelt opened this issue 1 month ago • 0 comments

We can actually check for panic being set to abort with a built-in cfg macro. I guess this way we can make a safe version of the replace_with_or_abort_unchecked function:

#[inline]
#[cfg(panic = "abort")]
pub fn replace_with_or_abort_unchecked<T, F: FnOnce(T) -> T>(dest: &mut T, f: F) {
    unsafe { ptr::write(dest, f(ptr::read(dest))); }
}

sentinelt avatar May 18 '24 06:05 sentinelt