Rollup merge of #80438 - crlf0710:box_into_inner, r=m-ou-se

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`
This commit is contained in:
Yuki Okushi 2021-02-10 12:24:19 +09:00 committed by GitHub
commit a28f2afbeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -509,6 +509,23 @@ pub fn into_boxed_slice(boxed: Self) -> Box<[T], A> {
let (raw, alloc) = Box::into_raw_with_allocator(boxed); let (raw, alloc) = Box::into_raw_with_allocator(boxed);
unsafe { Box::from_raw_in(raw as *mut [T; 1], alloc) } 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]> { impl<T> Box<[T]> {