]>
git.proxmox.com Git - rustc.git/blob - vendor/rustix-0.36.5/src/utils.rs
1 /// Convert a `&T` into a `*const T` without using an `as`.
4 pub(crate) const fn as_ptr
<T
>(t
: &T
) -> *const T
{
8 /// Convert a `&mut T` into a `*mut T` without using an `as`.
11 pub(crate) fn as_mut_ptr
<T
>(t
: &mut T
) -> *mut T
{
15 /// Convert a `*mut c_void` to a `*mut T`, checking that it is not null,
16 /// misaligned, or pointing to a region of memory that wraps around the address
19 pub(crate) fn check_raw_pointer
<T
>(value
: *mut core
::ffi
::c_void
) -> Option
<core
::ptr
::NonNull
<T
>> {
21 .checked_add(core
::mem
::size_of
::<T
>())
23 || (value
as usize) % core
::mem
::align_of
::<T
>() != 0
28 core
::ptr
::NonNull
::new(value
.cast())