use std::ptr::NonNull; pub(crate) fn heap_move(x: T) -> *mut T { Box::into_raw(Box::new(x)) } pub(crate) fn heap_move_nonnull(x: T) -> NonNull { NonNull::from(Box::leak(Box::new(x))) } pub(crate) fn heap_move_ok(x: Result) -> *mut T { x.map(|x| heap_move(x)).unwrap_or(std::ptr::null_mut()) } pub(crate) fn heap_move_some(x: Option) -> *mut T { x.map(|x| heap_move(x)).unwrap_or(std::ptr::null_mut()) } pub(crate) unsafe fn heap_drop(x: NonNull) { drop(unsafe { heap_remove(x) }); } pub(crate) unsafe fn heap_remove(x: NonNull) -> T { unsafe { *Box::from_raw(x.as_ptr()) } } pub(crate) unsafe fn heap_clone(source: NonNull) -> NonNull { heap_move_nonnull(unsafe { source.as_ref().clone() }) }