1
0
Fork 0
forked from wry/wry
wry/src/utils/ptr_ext.rs
2024-10-20 18:39:11 +02:00

28 lines
584 B
Rust

pub trait PtrExt<T: ?Sized> {
unsafe fn deref<'a>(self) -> &'a T;
}
pub trait MutPtrExt<T: ?Sized> {
unsafe fn deref_mut<'a>(self) -> &'a mut T;
}
impl<T: ?Sized> PtrExt<T> for *const T {
#[inline(always)]
unsafe fn deref<'a>(self) -> &'a T {
unsafe { &*self }
}
}
impl<T: ?Sized> PtrExt<T> for *mut T {
#[inline(always)]
unsafe fn deref<'a>(self) -> &'a T {
unsafe { &*self }
}
}
impl<T: ?Sized> MutPtrExt<T> for *mut T {
#[inline(always)]
unsafe fn deref_mut<'a>(self) -> &'a mut T {
unsafe { &mut *self }
}
}