pub struct DroppingFlag<T> { /* private fields */ }
Expand description
A wrapper for managing when a value gets dropped via a DropFlag
.
This type tracks the destruction state of some value relative to another
value via its DropFlag
: for example, it might be the storage of a value
wrapped up in a MoveRef
. When a DroppingFlag
is destroyed, it will
run the destructor for the wrapped value if and only if the DropFlag
is dead.
This type can be viewed as using a DropFlag
to “complete” a
ManuallyDrop<T>
by explicitly tracking whether it has been dropped. The
flag can be used to signal whether to destroy or leak the value, but the
destruction occurs lazily rather than immediately when the flag is flipped.
This is useful as an AsMove::Storage
type for types where the storage
should be leaked if the inner type was somehow not destroyed, such as in
the case of heap-allocated storage like Box<T>
.
Implementations§
Source§impl<T> DroppingFlag<T>
impl<T> DroppingFlag<T>
Sourcepub fn new(value: T) -> Self
pub fn new(value: T) -> Self
Wraps a new value to have its drop state managed by a DropFlag
.
The drop flag will start out dead and needs to be manually incremented.
Sourcepub fn flag(slot: &Self) -> DropFlag<'_>
pub fn flag(slot: &Self) -> DropFlag<'_>
Gets a reference to the drop flag.
This function is safe; the returned reference to the drop flag cannot be used to make a previously dropped value live again.
Sourcepub fn as_parts(slot: &Self) -> (&T, DropFlag<'_>)
pub fn as_parts(slot: &Self) -> (&T, DropFlag<'_>)
Splits this slot into a reference to the wrapped value plus a reference to the drop flag.
This function is safe; the returned reference to the drop flag cannot be used to make a previously dropped value live again, since the value is not destroyed before the wrapper is.
Sourcepub fn as_parts_mut(slot: &mut Self) -> (&mut T, DropFlag<'_>)
pub fn as_parts_mut(slot: &mut Self) -> (&mut T, DropFlag<'_>)
Splits this slot into a reference to the wrapped value plus a reference to the drop flag.
This function is safe; the returned reference to the drop flag cannot be used to make a previously dropped value live again, since the value is not destroyed before the wrapper is.