use core::{hint, mem, ptr};
#[inline]
#[cfg_attr(miri, track_caller)] #[expect(clippy::cast_sign_loss)]
#[expect(clippy::checked_conversions)]
pub(crate) unsafe fn offset_from_unsigned<T>(this: *const T, origin: *const T) -> usize {
unsafe {
hint::assert_unchecked(this >= origin);
let pointee_size = mem::size_of::<T>();
assert!(0 < pointee_size && pointee_size <= isize::MAX as usize);
this.offset_from(origin) as usize
}
}
#[inline(always)]
pub(crate) unsafe fn write_with<T>(ptr: *mut T, f: impl FnOnce() -> T) {
unsafe { ptr::write(ptr, f()) };
}