pub struct PtrConst<'mem>(/* private fields */);
Expand description
A type-erased read-only pointer to an initialized value.
Cannot be null. May be dangling (for ZSTs)
Implementations§
Source§impl<'mem> PtrConst<'mem>
impl<'mem> PtrConst<'mem>
Sourcepub const fn new<T>(ptr: *const T) -> Self
pub const fn new<T>(ptr: *const T) -> Self
Create a new opaque const pointer from a raw pointer
§Safety
The pointer must be non-null, valid, aligned, and point to initialized memory
of the correct type, and be valid for lifetime 'mem
.
It’s encouraged to take the address of something with &raw const x
, rather than &x
Sourcepub const fn as_byte_ptr(self) -> *const u8
pub const fn as_byte_ptr(self) -> *const u8
Gets the underlying raw pointer as a byte pointer
Sourcepub const unsafe fn as_ptr<T>(self) -> *const T
pub const unsafe fn as_ptr<T>(self) -> *const T
Gets the underlying raw pointer as a pointer of type T
§Safety
Must be called with the original type T that was used to create this pointer
Sourcepub const unsafe fn get<'borrow: 'mem, T>(self) -> &'borrow T
pub const unsafe fn get<'borrow: 'mem, T>(self) -> &'borrow T
Gets the underlying raw pointer as a const pointer of type T
§Safety
T
must be the actual underlying type. You’re downcasting with no guardrails.
Sourcepub const unsafe fn field(self, offset: usize) -> PtrConst<'mem>
pub const unsafe fn field(self, offset: usize) -> PtrConst<'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.
Sourcepub const unsafe fn read<T>(self) -> T
pub const unsafe fn read<T>(self) -> T
Exposes core::ptr::read
§Safety
T
must be the actual underlying type of the pointed-to memory.
The memory must be properly initialized and aligned for type T
.