GenericPtr

Enum GenericPtr 

Source
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>

Source

pub fn new<T: ?Sized>(ptr: *const T) -> Self

Returns the size of the pointer, which may be thin or wide.

Source

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.

Source

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.

Source

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.

Source

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

Source

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>

Source§

fn clone(&self) -> GenericPtr<'mem>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> From<PtrConst<'a>> for GenericPtr<'a>

Source§

fn from(value: PtrConst<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<PtrConstWide<'a>> for GenericPtr<'a>

Source§

fn from(value: PtrConstWide<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'mem> Copy for GenericPtr<'mem>

Auto Trait Implementations§

§

impl<'mem> Freeze for GenericPtr<'mem>

§

impl<'mem> RefUnwindSafe for GenericPtr<'mem>

§

impl<'mem> !Send for GenericPtr<'mem>

§

impl<'mem> !Sync for GenericPtr<'mem>

§

impl<'mem> Unpin for GenericPtr<'mem>

§

impl<'mem> UnwindSafe for GenericPtr<'mem>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.