pub struct OpaqueUninit<'mem>(/* private fields */);Expand description
A type-erased pointer to an uninitialized value
Implementations§
Source§impl<'mem> OpaqueUninit<'mem>
impl<'mem> OpaqueUninit<'mem>
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) -> Opaque<'mem>
pub unsafe fn assume_init(self) -> Opaque<'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) -> Opaque<'mem>
pub unsafe fn put<T>(self, value: T) -> Opaque<'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 unsafe fn write(self, source: OpaqueConst<'_>) -> Opaque<'mem>
pub unsafe fn write(self, source: OpaqueConst<'_>) -> Opaque<'mem>
Copies data from the source pointer to this location and converts to an initialized pointer
§Safety
- The destination pointer must be properly aligned and point to allocated memory that can be safely written to.
- The source pointer must point to properly initialized data.
- Both pointers must refer to objects of the same type and size.
Sourcepub fn as_mut_bytes(self) -> *mut u8
pub fn as_mut_bytes(self) -> *mut u8
Returns the underlying raw pointer as a byte pointer
Sourcepub unsafe fn field_uninit(self, offset: usize) -> OpaqueUninit<'mem>
pub unsafe fn field_uninit(self, offset: usize) -> OpaqueUninit<'mem>
Returns a pointer with the given offset added
§Safety
Offset is within the bounds of the allocated memory
Sourcepub unsafe fn field_init(self, offset: usize) -> Opaque<'mem>
pub unsafe fn field_init(self, offset: usize) -> Opaque<'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
Trait Implementations§
Source§impl<'mem> Clone for OpaqueUninit<'mem>
impl<'mem> Clone for OpaqueUninit<'mem>
Source§fn clone(&self) -> OpaqueUninit<'mem>
fn clone(&self) -> OpaqueUninit<'mem>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more