pub struct PtrUninit<'mem>(/* private fields */);
Expand description
A type-erased pointer to an uninitialized value
Implementations§
Source§impl<'mem> PtrUninit<'mem>
impl<'mem> PtrUninit<'mem>
Sourcepub unsafe fn copy_from<'src>(
self,
src: PtrConst<'src>,
shape: &'static Shape,
) -> Result<PtrMut<'mem>, UnsizedError>
pub unsafe fn copy_from<'src>( self, src: PtrConst<'src>, shape: &'static Shape, ) -> Result<PtrMut<'mem>, UnsizedError>
Copies memory from a source pointer into this location and returns PtrMut
§Safety
- The source pointer must be valid for reads of
len
bytes - This pointer must be valid for writes of
len
bytes and properly aligned - The regions may not overlap
Sourcepub fn new<T>(ptr: *mut T) -> Self
pub fn new<T>(ptr: *mut T) -> Self
Create a new opaque pointer from a mutable pointer
This is safe because it’s generic over T
Sourcepub fn from_maybe_uninit<T>(borrow: &'mem mut MaybeUninit<T>) -> Self
pub fn from_maybe_uninit<T>(borrow: &'mem mut MaybeUninit<T>) -> Self
Creates a new opaque pointer from a reference to a core::mem::MaybeUninit
The pointer will point to the potentially uninitialized contents
This is safe because it’s generic over T
Sourcepub unsafe fn assume_init(self) -> PtrMut<'mem>
pub unsafe fn assume_init(self) -> PtrMut<'mem>
Assumes the pointer is initialized and returns an Opaque
pointer
§Safety
The pointer must actually be pointing to initialized memory of the correct type.
Sourcepub unsafe fn put<T>(self, value: T) -> PtrMut<'mem>
pub unsafe fn put<T>(self, value: T) -> PtrMut<'mem>
Write a value to this location and convert to an initialized pointer
§Safety
The pointer must be properly aligned for T and point to allocated memory that can be safely written to.
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 byte 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
Sourcepub unsafe fn field_uninit_at(self, offset: usize) -> PtrUninit<'mem>
pub unsafe fn field_uninit_at(self, offset: usize) -> PtrUninit<'mem>
Returns a pointer with the given offset added
§Safety
Offset is within the bounds of the allocated memory
Sourcepub unsafe fn field_init_at(self, offset: usize) -> PtrMut<'mem>
pub unsafe fn field_init_at(self, offset: usize) -> PtrMut<'mem>
Returns a pointer with the given offset added, assuming it’s initialized
§Safety
The pointer plus offset must be:
- Within bounds of the allocated object
- Properly aligned for the type being pointed to
- Point to initialized data of the correct type