pub struct PtrConst<'mem> { /* private fields */ }Expand description
A type-erased, read-only wide pointer to an initialized value.
Like PtrConst, but for unsized types where metadata is needed. Cannot be null
(but may be dangling for ZSTs). The lifetime 'mem represents the borrow of the
underlying memory, which must remain valid and initialized.
Implementations§
Source§impl<'mem> PtrConst<'mem>
impl<'mem> PtrConst<'mem>
Sourcepub const fn as_byte_ptr(self) -> *const u8
pub const fn as_byte_ptr(self) -> *const u8
Returns the underlying data pointer as a pointer to u8 (the address of the object).
Sourcepub const unsafe fn get<T: ?Sized>(self) -> &'mem T
pub const unsafe fn get<T: ?Sized>(self) -> &'mem T
Borrows the underlying object as a reference of type T.
§Safety
Tmust be the actual underlying (potentially unsized) type of the pointed-to memory.- The memory must remain valid and not be mutated while this reference exists.
- The pointer must be correctly aligned and point to a valid, initialized value for type
T.
Sourcepub const unsafe fn as_ptr<T: ?Sized>(self) -> *const T
pub const unsafe fn as_ptr<T: ?Sized>(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 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.