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>

source

pub const fn new(value: T) -> MaybeDangling<T>

source

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>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for MaybeDangling<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

source§

impl<T: Default> Default for MaybeDangling<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T> Deref for MaybeDangling<T>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &T

Dereferences the value.
source§

impl<T> DerefMut for MaybeDangling<T>

source§

fn deref_mut(&mut self) -> &mut T

Mutably dereferences the value.
source§

impl<T> Drop for MaybeDangling<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T: Hash> Hash for MaybeDangling<T>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T: Ord> Ord for MaybeDangling<T>

source§

fn cmp(&self, other: &Self) -> Ordering

1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl<T: PartialEq> PartialEq<MaybeDangling<T>> for MaybeDangling<T>

source§

fn eq(&self, other: &Self) -> bool

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: PartialOrd> PartialOrd<MaybeDangling<T>> for MaybeDangling<T>

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T: Eq> Eq for MaybeDangling<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for MaybeDangling<T>where T: RefUnwindSafe,

§

impl<T> Send for MaybeDangling<T>where T: Send,

§

impl<T> Sync for MaybeDangling<T>where T: Sync,

§

impl<T> Unpin for MaybeDangling<T>where T: Unpin,

§

impl<T> UnwindSafe for MaybeDangling<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.