Struct maybe_dangling::ManuallyDrop
source · #[repr(transparent)]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. -
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.
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§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
See ::core::mem::ManuallyDrop::fmt() for more info.
See ::core::mem::ManuallyDrop::fmt() for more info.
source§impl<T: Default> Default for ManuallyDrop<T>
impl<T: Default> Default for ManuallyDrop<T>
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§fn hash<__H: Hasher>(&self, state: &mut __H)
fn hash<__H: Hasher>(&self, state: &mut __H)
See ::core::mem::ManuallyDrop::hash() for more info.
See ::core::mem::ManuallyDrop::hash() for more info.
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.
See ::core::mem::ManuallyDrop::cmp() for more info.
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl<T: PartialEq> PartialEq<ManuallyDrop<T>> for ManuallyDrop<T>
impl<T: PartialEq> PartialEq<ManuallyDrop<T>> for ManuallyDrop<T>
source§fn eq(&self, other: &Self) -> bool
fn eq(&self, other: &Self) -> bool
See ::core::mem::ManuallyDrop::eq() for more info.
See ::core::mem::ManuallyDrop::eq() for more info.
source§impl<T: PartialOrd> PartialOrd<ManuallyDrop<T>> for ManuallyDrop<T>
impl<T: PartialOrd> PartialOrd<ManuallyDrop<T>> for ManuallyDrop<T>
source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
See ::core::mem::ManuallyDrop::partial_cmp() for more info.
See ::core::mem::ManuallyDrop::partial_cmp() for more info.
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more