Skip to content

Commit

Permalink
Add Box::into_inner.
Browse files Browse the repository at this point in the history
  • Loading branch information
crlf0710 committed Feb 9, 2021
1 parent 26438b4 commit ce7de07
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,23 @@ impl<T, A: Allocator> Box<T, A> {
let (raw, alloc) = Box::into_raw_with_allocator(boxed);
unsafe { Box::from_raw_in(raw as *mut [T; 1], alloc) }
}

/// Consumes the `Box`, returning the wrapped value.
///
/// # Examples
///
/// ```
/// #![feature(box_into_inner)]
///
/// let c = Box::new(5);
///
/// assert_eq!(Box::into_inner(c), 5);
/// ```
#[unstable(feature = "box_into_inner", issue = "80437")]
#[inline]
pub fn into_inner(boxed: Self) -> T {
*boxed
}
}

impl<T> Box<[T]> {
Expand Down

0 comments on commit ce7de07

Please sign in to comment.