-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
uhm, put back ptr fns and something?
still, not sure if I like this lol, but it's, something
- Loading branch information
Showing
6 changed files
with
43 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,41 @@ | ||
pub trait PtrExt { | ||
type Out; | ||
fn ref_to_ptr(&self) -> *const Self::Out; | ||
fn ref_to_ptr_mut(&mut self) -> *mut Self::Out; | ||
} | ||
|
||
impl<T> PtrExt for T { | ||
type Out = T; | ||
use std::ops::{ Deref, DerefMut }; | ||
|
||
#[inline(always)] | ||
fn ref_to_ptr(&self) -> *const T { | ||
self | ||
} | ||
#[inline(always)] | ||
pub fn coerce_ptr<T: ?Sized>(thing: &T) -> *const T { | ||
thing | ||
} | ||
|
||
#[inline(always)] | ||
fn ref_to_ptr_mut(&mut self) -> *mut T { | ||
self | ||
} | ||
#[inline(always)] | ||
pub fn coerce_ptr_mut<T: ?Sized>(thing: &mut T) -> *mut T { | ||
thing | ||
} | ||
|
||
impl<T> PtrExt for [T] { | ||
type Out = T; | ||
#[inline(always)] | ||
pub fn coerce_slice_ptr<T>(thing: &[T]) -> *const T { | ||
coerce_ptr(thing).cast() | ||
} | ||
|
||
#[inline(always)] | ||
fn ref_to_ptr(&self) -> *const T { | ||
self.as_ptr() | ||
} | ||
#[inline(always)] | ||
pub fn coerce_slice_ptr_mut<T>(thing: &mut [T]) -> *mut T { | ||
coerce_ptr_mut(thing).cast() | ||
} | ||
|
||
#[inline(always)] | ||
fn ref_to_ptr_mut(&mut self) -> *mut T { | ||
self.as_mut_ptr() | ||
} | ||
#[inline(always)] | ||
pub unsafe fn reborrow<'h, T: ?Sized>(thing: *const T) -> &'h T { | ||
unsafe { &*thing } | ||
} | ||
|
||
pub trait PtrSliceExt { | ||
fn slice_to_ptr(&self) -> *const Self; | ||
fn slice_to_ptr_mut(&mut self) -> *mut Self; | ||
#[inline(always)] | ||
pub unsafe fn reborrow_mut<'h, T: ?Sized>(thing: *mut T) -> &'h mut T { | ||
unsafe { &mut *thing } | ||
} | ||
|
||
impl<T> PtrSliceExt for [T] { | ||
#[inline(always)] | ||
fn slice_to_ptr(&self) -> *const [T] { | ||
self | ||
} | ||
#[inline(always)] | ||
pub unsafe fn deref_ptr<T: Deref>(thing: *const T) -> *const T::Target { | ||
unsafe { &**thing } | ||
} | ||
|
||
#[inline(always)] | ||
fn slice_to_ptr_mut(&mut self) -> *mut [T] { | ||
self | ||
} | ||
#[inline(always)] | ||
pub unsafe fn deref_ptr_mut<T: DerefMut>(thing: *mut T) -> *mut T::Target { | ||
unsafe { &mut **thing } | ||
} |