pub struct ManuallyDrop<T> { /* private fields */ }Expand description
A wrapper to inhibit compiler from automatically calling T’s destructor.
This wrapper is 0-cost.
See ::core::mem::ManuallyDrop for more info.
§Differences with ::core::mem::ManuallyDrop
-
No niches
The current implementation uses
::core::mem::MaybeUninitto make sure the aliasing anddereferenceableity properties of the innerTare properly disabled.The main side-effect of this implementation is that it disables niches, thereby preventing discriminant elision.
For instance, an
Option<ManuallyDrop<bool>>will occupy two bytes rather than one. -
It does not implement [
Structural{Partial,}Eq][::core::marker::StructuralEq]. -
Note that once stdlib’s own
::core::mem::ManuallyDropproperly gets its aliasing/dereferenceableity properties removed, this crate shall be updated to just reëxport it (using abuild.rsto prevent MSRV breakage).This means that the lack of discriminant elision cannot be relied upon either!
-
Other than that, this is a
#[repr(transparent)]wrapper aroundT, thereby having:
this is assuming
MaybeUninit<T>has the same ABI asT, as it currently advertises, despite that probably being a bad idea for a “bag of bytes”T-ish wrapper, since it means that padding bytes inside ofTwon’t be preserved when working with aMaybeUninit<T>. So, if the stdlib were to break the current ABI promise ofMaybeUninitto cater to that problem, then this crate would probably do so well, unless themaybe_danglingchanges were to make it to the stdlib first. ↩
Implementations§
Source§impl<T> ManuallyDrop<T>
impl<T> ManuallyDrop<T>
Sourcepub const fn new(value: T) -> ManuallyDrop<T>
pub const fn new(value: T) -> ManuallyDrop<T>
Wrap a value to be manually dropped.
See ::core::mem::ManuallyDrop::new() for more info.
Sourcepub const fn into_inner(slot: ManuallyDrop<T>) -> T
pub const fn into_inner(slot: ManuallyDrop<T>) -> T
Extracts the value from the ManuallyDrop container.
See ::core::mem::ManuallyDrop::into_inner() for more info.
Sourcepub unsafe fn take(slot: &mut ManuallyDrop<T>) -> T
pub unsafe fn take(slot: &mut ManuallyDrop<T>) -> T
Takes the value from the ManuallyDrop<T> container out.
See ::core::mem::ManuallyDrop::take() for more info.
Sourcepub unsafe fn drop(slot: &mut ManuallyDrop<T>)
pub unsafe fn drop(slot: &mut ManuallyDrop<T>)
Manually drops the contained value.
See ::core::mem::ManuallyDrop::drop() for more info.
Trait Implementations§
Source§impl<T: Clone> Clone for ManuallyDrop<T>
impl<T: Clone> Clone for ManuallyDrop<T>
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
See ::core::mem::ManuallyDrop::clone() for more info.
Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
See ::core::mem::ManuallyDrop::clone_from() for more info.
Source§impl<T: Debug> Debug for ManuallyDrop<T>
impl<T: Debug> Debug for ManuallyDrop<T>
Source§impl<T: Default> Default for ManuallyDrop<T>
impl<T: Default> Default for ManuallyDrop<T>
Source§fn default() -> Self
fn default() -> Self
See ::core::mem::ManuallyDrop::default() for more info.
Source§impl<T> Deref for ManuallyDrop<T>
impl<T> Deref for ManuallyDrop<T>
Source§impl<T> DerefMut for ManuallyDrop<T>
impl<T> DerefMut for ManuallyDrop<T>
Source§fn deref_mut(&mut self) -> &mut T
fn deref_mut(&mut self) -> &mut T
See ::core::mem::ManuallyDrop::deref_mut() for more info.
Source§impl<T: Hash> Hash for ManuallyDrop<T>
impl<T: Hash> Hash for ManuallyDrop<T>
Source§impl<T: Ord> Ord for ManuallyDrop<T>
impl<T: Ord> Ord for ManuallyDrop<T>
Source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
See ::core::mem::ManuallyDrop::cmp() for more info.