pub struct Slot<'a, T: ?Sized> { /* private fields */ }
Expand description
A memory location that may or may not have a value initialized in it.
Implementations
sourceimpl<'a, T: ?Sized> Slot<'a, T>
impl<'a, T: ?Sized> Slot<'a, T>
sourcepub fn pointer_layout(&self) -> Layoutwhere
T: Pointee,
T::Metadata: Metadata<T>,
pub fn pointer_layout(&self) -> Layoutwhere
T: Pointee,
T::Metadata: Metadata<T>,
Returns the layout of the pointer held in the slot.
sourcepub unsafe fn new_unchecked(ptr: *mut T) -> Self
pub unsafe fn new_unchecked(ptr: *mut T) -> Self
Creates a new slot from an exclusive pointer.
Safety
ptr
must be non-null, properly aligned, and valid for reads and writes.ptr
must not alias any other accessible references for'a
.
sourcepub unsafe fn assume_init_ref(&self) -> &'a T
pub unsafe fn assume_init_ref(&self) -> &'a T
Gets a shared reference to the value in the slot.
Safety
The contents of the slot must be initialized. See assume_init
for
details.
sourcepub unsafe fn assume_init_mut(&mut self) -> &'a mut T
pub unsafe fn assume_init_mut(&mut self) -> &'a mut T
Gets a mutable reference to the value in the slot.
Safety
The contents of the slot must be initialized. See assume_init
for
details.
sourcepub unsafe fn assume_init_drop(&mut self)
pub unsafe fn assume_init_drop(&mut self)
Drops the value in the slot.
Safety
The contents of the slot must be initialized. See assume_init
for
details.
sourcepub fn as_mut<'b>(&'b mut self) -> Slot<'b, T>where
'a: 'b,
pub fn as_mut<'b>(&'b mut self) -> Slot<'b, T>where
'a: 'b,
Gets a mutable borrow from this slot.
sourcepub fn zero(&mut self)where
T: Pointee,
T::Metadata: Metadata<T>,
pub fn zero(&mut self)where
T: Pointee,
T::Metadata: Metadata<T>,
Writes zeroes to every byte of the backing memory.
sourcepub fn as_bytes(self) -> Slot<'a, [u8]>where
T: Pointee,
T::Metadata: Metadata<T>,
pub fn as_bytes(self) -> Slot<'a, [u8]>where
T: Pointee,
T::Metadata: Metadata<T>,
Returns a slot of the underlying bytes.
sourcepub fn cast_checked<U>(self) -> Option<Slot<'a, U>>where
T: Pointee,
T::Metadata: Metadata<T>,
pub fn cast_checked<U>(self) -> Option<Slot<'a, U>>where
T: Pointee,
T::Metadata: Metadata<T>,
Attempts to cast the type of the Slot
from T
to U
.
Returns None
if U
requires a higher alignment than the pointer in
self
or U
is larger than T
.
sourcepub unsafe fn cast<U>(self) -> Slot<'a, U>
pub unsafe fn cast<U>(self) -> Slot<'a, U>
Casts the type of the Slot
from T
to U
.
Safety
The slot must point to memory suitable for holding a U
. In addition to
being the right size and aligment, the caller must also guarantee that
the slot pointer will not alias any other accessible references after
being cast.
sourceimpl<'a, T> Slot<'a, T>
impl<'a, T> Slot<'a, T>
sourcepub fn new(value: &'a mut MaybeUninit<T>) -> Self
pub fn new(value: &'a mut MaybeUninit<T>) -> Self
Returns a new Slot
backed by the given MaybeUninit
.
sourcepub fn write(&mut self, value: T) -> &mut T
pub fn write(&mut self, value: T) -> &mut T
Sets the value of the Slot
.
This overwrites any previous value without dropping it, so be careful not to use this after initializing the slot unless you want to skip running the destructor.
Because this method does not convert the Slot
to a value, the written
value will not be dropped when the returned reference or underlying
Slot
leave scope.
sourcepub fn as_maybe_uninit(&self) -> &MaybeUninit<T>
pub fn as_maybe_uninit(&self) -> &MaybeUninit<T>
Returns a reference to the underlying memory as a MaybeUninit
.
sourcepub fn as_maybe_uninit_mut(&mut self) -> &mut MaybeUninit<T>
pub fn as_maybe_uninit_mut(&mut self) -> &mut MaybeUninit<T>
Returns a reference to the underlying memory as a mutable MaybeUninit
.