pub struct StuffedPtr<T, S, B = usize>(/* private fields */)
where
S: StuffingStrategy<B>,
B: Backend<T>;
Expand description
A union of a pointer or some other
data, bitpacked into a value with the size depending on
B
. It defaults to usize
, meaning pointer sized, but u64
and u128
are also provided
by this crate. You can also provide your own Backend
implementation
The stuffing strategy is supplied as the second generic parameter S
.
The first generic parameter T
is the type that the pointer is pointing to.
For a usage example, view the crate level documentation.
This pointer does not drop other
data, StuffedPtr::into_other
can be used if that is required.
StuffedPtr
implements most traits like Clone
, PartialEq
or Copy
if the other
type does.
This type is guaranteed to be #[repr(transparent)]
to a B::Stored
.
Implementations§
Source§impl<T, S, B> StuffedPtr<T, S, B>where
S: StuffingStrategy<B>,
B: Backend<T>,
impl<T, S, B> StuffedPtr<T, S, B>where
S: StuffingStrategy<B>,
B: Backend<T>,
Sourcepub fn get_ptr(&self) -> Option<*mut T>
pub fn get_ptr(&self) -> Option<*mut T>
Get the pointer data, or None
if it contains other
data
Sourcepub unsafe fn get_ptr_unchecked(&self) -> *mut T
pub unsafe fn get_ptr_unchecked(&self) -> *mut T
Get the unstuffed pointer data from the stuffed pointer, assuming that the StuffedPtr
contains pointer data.
§Safety
StuffedPtr
must contain pointer data and not other
data
Sourcepub fn into_other(self) -> Option<S::Other>
pub fn into_other(self) -> Option<S::Other>
Get owned other
data from this, or None
if it contains pointer data
Sourcepub unsafe fn into_other_unchecked(self) -> S::Other
pub unsafe fn into_other_unchecked(self) -> S::Other
Sourcepub unsafe fn get_other(&self) -> Option<S::Other>
pub unsafe fn get_other(&self) -> Option<S::Other>
Get other
data from this, or None
if it contains pointer data
§Safety
The caller must guarantee that only ever on Other
exists if Other: !Copy
Sourcepub unsafe fn get_other_unchecked(&self) -> S::Other
pub unsafe fn get_other_unchecked(&self) -> S::Other
Get other
data from this
§Safety
Must contain other
data and not pointer data,
and the caller must guarantee that only ever on Other
exists if Other: !Copy
Source§impl<T, S, B> StuffedPtr<T, S, B>
Extra implementations if the other
type is Copy
impl<T, S, B> StuffedPtr<T, S, B>
Extra implementations if the other
type is Copy
Sourcepub fn copy_other(&self) -> Option<S::Other>
pub fn copy_other(&self) -> Option<S::Other>
Get other
data from this, or None
if it’s pointer data