Struct maybe_dangling::MaybeDangling
source · pub struct MaybeDangling<T> { /* private fields */ }Expand description
Like crate::ManuallyDrop but for having drop glue.
This wrapper is 0-cost.
In other words, a MaybeDangling<T> is just like T, but
for having been stripped of aliasing/dereferenceable-ity properties.
Its usage should be quite rare and advanced: if you are intending to keep hold of a potentially dangling / exhausted value, chances are you won’t want implicit/automatic drop glue of it without having previously checked for lack of exhaustion ⚠️.
That is, it is strongly advisable to be using
crate::ManuallyDrop<T> instead!
Opting into #[may_dangle] and the dropck_eyepatch
Ironically, for this drop glue to be as smooth as it should be, the unstable
#[may_dangle] feature is needed.
But by virtue of being unstable, it cannot be offered by this crate on stable Rust.
For the adventurous nightly users, you can enable the
nightly-dropck_eyepatch Cargo feature to opt into the usage of the
eponymous rustc feature so as to get the Drop impl amended accordingly.
Implementations§
source§impl<T> MaybeDangling<T>
impl<T> MaybeDangling<T>
pub const fn new(value: T) -> MaybeDangling<T>
sourcepub fn into_inner(slot: MaybeDangling<T>) -> T
pub fn into_inner(slot: MaybeDangling<T>) -> T
Extracts the value from the MaybeDangling container.
See ::core::mem::ManuallyDrop::into_inner() for more info.
Trait Implementations§
source§impl<T: Clone> Clone for MaybeDangling<T>
impl<T: Clone> Clone for MaybeDangling<T>
source§impl<T: Debug> Debug for MaybeDangling<T>
impl<T: Debug> Debug for MaybeDangling<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 MaybeDangling<T>
impl<T: Default> Default for MaybeDangling<T>
source§impl<T> Deref for MaybeDangling<T>
impl<T> Deref for MaybeDangling<T>
source§impl<T> DerefMut for MaybeDangling<T>
impl<T> DerefMut for MaybeDangling<T>
source§impl<T> Drop for MaybeDangling<T>
impl<T> Drop for MaybeDangling<T>
source§impl<T: Hash> Hash for MaybeDangling<T>
impl<T: Hash> Hash for MaybeDangling<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 MaybeDangling<T>
impl<T: Ord> Ord for MaybeDangling<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<MaybeDangling<T>> for MaybeDangling<T>
impl<T: PartialEq> PartialEq<MaybeDangling<T>> for MaybeDangling<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<MaybeDangling<T>> for MaybeDangling<T>
impl<T: PartialOrd> PartialOrd<MaybeDangling<T>> for MaybeDangling<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