#[lang = "manually_drop"]
#[repr(transparent)]
pub struct ManuallyDrop<T> where
T: ?Sized, { /* fields omitted */ }
A wrapper to inhibit compiler from automatically calling T
’s destructor.
This wrapper is 0-cost.
This wrapper helps with explicitly documenting the drop order dependencies between fields of
the type:
use std::mem::ManuallyDrop;
struct Peach;
struct Banana;
struct Melon;
struct FruitBox {
peach: ManuallyDrop<Peach>,
melon: Melon,
banana: ManuallyDrop<Banana>,
}
impl Drop for FruitBox {
fn drop(&mut self) {
unsafe {
ManuallyDrop::drop(&mut self.peach);
ManuallyDrop::drop(&mut self.banana);
}
}
}
Wrap a value to be manually dropped.
use std::mem::ManuallyDrop;
ManuallyDrop::new(Box::new(()));
Extract the value from the ManuallyDrop
container.
This allows the value to be dropped again.
use std::mem::ManuallyDrop;
let x = ManuallyDrop::new(Box::new(()));
let _: Box<()> = ManuallyDrop::into_inner(x);
#[must_use = "if you don\'t need the value, you can use `ManuallyDrop::drop` instead"]
pub unsafe fn take(slot: &mut ManuallyDrop<T>) -> T
| [src] |
🔬 This is a nightly-only experimental API. (manually_drop_take
)
Takes the contained value out.
This method is primarily intended for moving out values in drop.
Instead of using ManuallyDrop::drop
to manually drop the value,
you can use this method to take the value and use it however desired.
Drop
will be invoked on the returned value following normal end-of-scope rules.
If you have ownership of the container, you can use ManuallyDrop::into_inner
instead.
This function semantically moves out the contained value without preventing further usage.
It is up to the user of this method to ensure that this container is not used again.
Manually drops the contained value.
If you have ownership of the value, you can use ManuallyDrop::into_inner
instead.
This function runs the destructor of the contained value and thus the wrapped value
now represents uninitialized data. It is up to the user of this method to ensure the
uninitialized data is not actually used.
Performs copy-assignment from source
. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self | 1.21.0 [src] |
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self | 1.21.0 [src] |
Compares and returns the minimum of two values. Read more
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
Feeds this value into the given [Hasher
]. Read more
Feeds a slice of this type into the given [Hasher
]. Read more
Formats the value using the given formatter. Read more
Returns the "default value" for a type. Read more
Mutably dereferences the value.
type Target = T
The resulting type after dereferencing.
type Owned = T
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
type Error = !
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
type Error = <U as TryFrom<T>>::Error
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static