pub enum GenericPtr<'mem> {
Thin(PtrConst<'mem>),
Wide(PtrConstWide<'mem>),
}
Expand description
A generic wrapper for either a thin or wide constant pointer. This enables working with both sized and unsized types using a single enum.
Variants§
Thin(PtrConst<'mem>)
A thin pointer, used for sized types.
Wide(PtrConstWide<'mem>)
A wide pointer, used for unsized types such as slices and trait objects.
Implementations§
Source§impl<'mem> GenericPtr<'mem>
impl<'mem> GenericPtr<'mem>
Sourcepub fn new<T: ?Sized>(ptr: *const T) -> Self
pub fn new<T: ?Sized>(ptr: *const T) -> Self
Returns the size of the pointer, which may be thin or wide.
Sourcepub fn thin(self) -> Option<PtrConst<'mem>>
pub fn thin(self) -> Option<PtrConst<'mem>>
Returns the inner PtrConst
if this is a thin pointer, or None
if this is a wide pointer.
Sourcepub fn wide(self) -> Option<PtrConstWide<'mem>>
pub fn wide(self) -> Option<PtrConstWide<'mem>>
Returns the inner PtrConstWide
if this is a wide pointer, or None
if this is a thin pointer.
Sourcepub unsafe fn get<T: ?Sized>(self) -> &'mem T
pub unsafe fn get<T: ?Sized>(self) -> &'mem T
Downcasts this pointer into a reference — wide or not
§Safety
The pointer must be valid for reads for the given type T
.
Sourcepub fn as_byte_ptr(self) -> *const u8
pub fn as_byte_ptr(self) -> *const u8
Returns the inner pointer as a raw (possibly wide) *const ()
.
If this is a thin pointer, the returned value is
Sourcepub unsafe fn field(self, offset: usize) -> GenericPtr<'mem>
pub unsafe fn field(self, offset: usize) -> GenericPtr<'mem>
Returns a pointer with the given offset added
§Safety
Offset must be within the bounds of the allocated memory, and the resulting pointer must be properly aligned.
Trait Implementations§
Source§impl<'mem> Clone for GenericPtr<'mem>
impl<'mem> Clone for GenericPtr<'mem>
Source§fn clone(&self) -> GenericPtr<'mem>
fn clone(&self) -> GenericPtr<'mem>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more