pub struct PtrUninit<'mem> { /* private fields */ }Expand description
A type-erased, wide pointer to an uninitialized value.
This can be useful for working with dynamically sized types, like slices or trait objects, where both a pointer and metadata (such as length or vtable) need to be stored.
The lifetime 'mem represents the borrow of the underlying uninitialized memory.
Implementations§
Source§impl<'mem> PtrUninit<'mem>
impl<'mem> PtrUninit<'mem>
Sourcepub const fn new<T: ?Sized>(ptr: NonNull<T>) -> Self
pub const fn new<T: ?Sized>(ptr: NonNull<T>) -> Self
Create a new opaque pointer from a mutable pointer
Sourcepub const unsafe fn copy_from<'src>(
self,
src: PtrConst<'src>,
shape: &'static Shape,
) -> Result<PtrMut<'mem>, UnsizedError>
pub const 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
lenbytes - This pointer must be valid for writes of
lenbytes and properly aligned - The regions may not overlap
Sourcepub const fn from_maybe_uninit<T>(borrow: &'mem mut MaybeUninit<T>) -> Self
pub const 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
Sourcepub const unsafe fn assume_init(self) -> PtrMut<'mem>
pub const 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 const unsafe fn put<T>(self, value: T) -> PtrMut<'mem>
pub const 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 const fn as_mut_byte_ptr(self) -> *mut u8
pub const fn as_mut_byte_ptr(self) -> *mut u8
Returns the underlying raw pointer as a byte pointer
Sourcepub const fn as_byte_ptr(self) -> *const u8
pub const fn as_byte_ptr(self) -> *const u8
Returns the underlying raw pointer as a const byte pointer
Sourcepub const unsafe fn field_uninit_at(self, offset: usize) -> PtrUninit<'mem>
pub const 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 const unsafe fn field_init_at(self, offset: usize) -> PtrMut<'mem>
pub const 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