Skip to content

Commit

Permalink
Rollup merge of #80438 - crlf0710:box_into_inner, r=m-ou-se
Browse files Browse the repository at this point in the history
Add `Box::into_inner`.

This adds a `Box::into_inner` method to the `Box` type. <del>I actually suggest deprecating the compiler magic of `*b` if this gets stablized in the future.</del>

r? `@m-ou-se`
  • Loading branch information
JohnTitor authored Feb 10, 2021
2 parents bb06b13 + ce7de07 commit a28f2af
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 @@ -509,6 +509,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 a28f2af

Please sign in to comment.