Skip to content

Commit

Permalink
Clarify ManuallyDrop docs
Browse files Browse the repository at this point in the history
Mention that you can use `into_inner` to drop the contained value.
  • Loading branch information
tbu- committed Sep 4, 2018
1 parent 4efc0a7 commit 0e62990
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/libcore/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,14 +971,16 @@ impl<T> ManuallyDrop<T> {
ManuallyDrop { value }
}

/// Extract the value from the ManuallyDrop container.
/// Extract the value from the `ManuallyDrop` container.
///
/// This allows the value to be dropped again.
///
/// # Examples
///
/// ```rust
/// use std::mem::ManuallyDrop;
/// let x = ManuallyDrop::new(Box::new(()));
/// let _: Box<()> = ManuallyDrop::into_inner(x);
/// let _: Box<()> = ManuallyDrop::into_inner(x); // This drops the `Box`.
/// ```
#[stable(feature = "manually_drop", since = "1.20.0")]
#[inline]
Expand All @@ -990,11 +992,15 @@ impl<T> ManuallyDrop<T> {
impl<T: ?Sized> ManuallyDrop<T> {
/// Manually drops the contained value.
///
/// If you have ownership of the value, you can use [`ManuallyDrop::into_inner`] instead.
///
/// # Safety
///
/// 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.
///
/// [`ManuallyDrop::into_inner`]: #method.into_inner
#[stable(feature = "manually_drop", since = "1.20.0")]
#[inline]
pub unsafe fn drop(slot: &mut ManuallyDrop<T>) {
Expand Down

0 comments on commit 0e62990

Please sign in to comment.