pub trait PointerExt: Sized
{
#[inline(always)]
fn offset_16(self) -> Memory
{
self._offset(16)
}
#[inline(always)]
fn offset_32(self) -> Memory
{
self._offset(32)
}
#[doc(hidden)]
#[inline(always)]
fn _offset(self, increment: usize) -> Memory
{
unsafe { NonNull::new_unchecked(self.to_memory().as_ptr().offset(increment as isize)) }
}
#[doc(hidden)]
#[inline(always)]
fn to_memory(self) -> Memory;
#[inline(always)]
fn is_not_null(self) -> bool;
}
impl PointerExt for *const u8
{
#[inline(always)]
fn to_memory(self) -> Memory
{
debug_assert!(self.is_not_null(), "is null");
unsafe { NonNull::new_unchecked(self as *mut _) }
}
#[inline(always)]
fn is_not_null(self) -> bool
{
!self.is_null()
}
}
impl PointerExt for *mut u8
{
#[inline(always)]
fn to_memory(self) -> Memory
{
debug_assert!(self.is_not_null(), "is null");
unsafe { NonNull::new_unchecked(self) }
}
#[inline(always)]
fn is_not_null(self) -> bool
{
!self.is_null()
}
}
impl PointerExt for *mut c_void
{
#[inline(always)]
fn to_memory(self) -> Memory
{
debug_assert!(self.is_not_null(), "is null");
unsafe { NonNull::new_unchecked(self as *mut u8) }
}
#[inline(always)]
fn is_not_null(self) -> bool
{
!self.is_null()
}
}
impl PointerExt for *mut i8
{
#[inline(always)]
fn to_memory(self) -> Memory
{
debug_assert!(self.is_not_null(), "is null");
unsafe { NonNull::new_unchecked(self as *mut u8) }
}
#[inline(always)]
fn is_not_null(self) -> bool
{
!self.is_null()
}
}
impl PointerExt for *const i8
{
#[inline(always)]
fn to_memory(self) -> Memory
{
debug_assert!(self.is_not_null(), "is null");
unsafe { NonNull::new_unchecked(self as *mut u8) }
}
#[inline(always)]
fn is_not_null(self) -> bool
{
!self.is_null()
}
}