1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#[inline]
#[allow(dead_code)]
pub(crate) const fn as_ptr<T>(t: &T) -> *const T {
t
}
#[inline]
#[allow(dead_code)]
pub(crate) fn as_mut_ptr<T>(t: &mut T) -> *mut T {
t
}
#[allow(dead_code)]
pub(crate) fn check_raw_pointer<T>(value: *mut core::ffi::c_void) -> Option<core::ptr::NonNull<T>> {
if (value as usize)
.checked_add(core::mem::size_of::<T>())
.is_none()
|| (value as usize) % core::mem::align_of::<T>() != 0
{
return None;
}
core::ptr::NonNull::new(value.cast())
}