pub struct DroppingSlot<'frame, T> { /* private fields */ }
Expand description
Similar to a Slot
, but able to drop its contents.
A DroppingSlot
wraps a Slot
, and will drop its contents if the
Slot
’s drop flag is dead at the time of the DroppingSlot
’s
destruction.
This type has an API similar to Slot
’s, but rather than returning
MoveRef
s, which would own the contents of this slot, we return a &mut T
and a DropFlag
, which the caller can assemble into an
appropriately-shaped MoveRef
. The drop flag will be one decrement away
from being dead; callers should make sure to decremement it to trigger
destruction.
DroppingSlot
is intended to be used with DerefMove::deref_move()
,
and will usually not be created by moveit
’s users. However, slot!()
provides DroppingSlot
support, too. These slots will silently forget their
contents if the drop flag is left untouched, rather than crash.
Implementations§
Source§impl<'frame, T> DroppingSlot<'frame, T>
impl<'frame, T> DroppingSlot<'frame, T>
Sourcepub unsafe fn new_unchecked(
ptr: &'frame mut MaybeUninit<T>,
drop_flag: DropFlag<'frame>,
) -> Self
pub unsafe fn new_unchecked( ptr: &'frame mut MaybeUninit<T>, drop_flag: DropFlag<'frame>, ) -> Self
Creates a new DroppingSlot
with the given pointer as its basis.
To safely construct a DroppingSlot
, use slot!()
.
§Safety
ptr
must not be outlived by any other pointers to its allocation.
drop_flag
’s value must be dead, and must be a drop flag governing
the destruction of ptr
’s storage in an appropriate manner as described
in moveit::drop_flag
.
Sourcepub fn put(self, val: T) -> (&'frame mut T, DropFlag<'frame>)
pub fn put(self, val: T) -> (&'frame mut T, DropFlag<'frame>)
Put val
into this slot, returning a reference to it.