pub struct PtrUninit { /* private fields */ }Expand description
A type-erased pointer to uninitialized memory.
Wraps PtrMut but represents uninitialized memory. No lifetime parameter.
Implementations§
Source§impl PtrUninit
impl PtrUninit
Sourcepub const fn new_sized<T: Sized>(ptr: *mut T) -> Self
pub const fn new_sized<T: Sized>(ptr: *mut T) -> Self
Create a new uninit pointer from a pointer to a sized type. This is const because sized types use thin pointers.
Sourcepub fn from_maybe_uninit<T>(borrow: &mut MaybeUninit<T>) -> Self
pub fn from_maybe_uninit<T>(borrow: &mut MaybeUninit<T>) -> Self
Creates from a reference to a MaybeUninit.
Sourcepub fn as_mut_byte_ptr(self) -> *mut u8
pub fn as_mut_byte_ptr(self) -> *mut u8
Returns the underlying raw pointer as a mutable byte pointer.
§Panics
Panics if this is a wide pointer.
Sourcepub fn as_byte_ptr(self) -> *const u8
pub fn as_byte_ptr(self) -> *const u8
Returns the underlying raw pointer as a const byte pointer.
§Panics
Panics if this is a wide pointer.
Sourcepub const unsafe fn assume_init(self) -> PtrMut
pub const unsafe fn assume_init(self) -> PtrMut
Assumes the pointer is initialized and returns a PtrMut.
§Safety
The memory must actually be initialized.
Sourcepub unsafe fn put<T>(self, value: T) -> PtrMut
pub unsafe fn put<T>(self, value: T) -> PtrMut
Write a value to this location and return an initialized pointer.
§Safety
The pointer must be properly aligned and point to allocated memory.
Sourcepub unsafe fn copy_from(
self,
src: PtrConst,
shape: &'static Shape,
) -> Result<PtrMut, UnsizedError>
pub unsafe fn copy_from( self, src: PtrConst, shape: &'static Shape, ) -> Result<PtrMut, UnsizedError>
Copies memory from a source pointer into this location.
§Safety
- The source pointer must be valid for reads
- This pointer must be valid for writes and properly aligned
- The regions may not overlap
Sourcepub unsafe fn field_uninit(self, offset: usize) -> PtrUninit
pub unsafe fn field_uninit(self, offset: usize) -> PtrUninit
Returns a pointer with the given offset added (still uninit).
§Safety
Offset must be within bounds of the allocated memory.
Sourcepub unsafe fn field_init(self, offset: usize) -> PtrMut
pub unsafe fn field_init(self, offset: usize) -> PtrMut
Returns a pointer with the given offset added, assuming it’s initialized.
§Safety
- Offset must be within bounds
- The memory at that offset must be initialized