Skip to content

Commit ce7de07

Browse files
committed
Add Box::into_inner.
1 parent 26438b4 commit ce7de07

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

library/alloc/src/boxed.rs

+17
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,23 @@ impl<T, A: Allocator> Box<T, A> {
495495
let (raw, alloc) = Box::into_raw_with_allocator(boxed);
496496
unsafe { Box::from_raw_in(raw as *mut [T; 1], alloc) }
497497
}
498+
499+
/// Consumes the `Box`, returning the wrapped value.
500+
///
501+
/// # Examples
502+
///
503+
/// ```
504+
/// #![feature(box_into_inner)]
505+
///
506+
/// let c = Box::new(5);
507+
///
508+
/// assert_eq!(Box::into_inner(c), 5);
509+
/// ```
510+
#[unstable(feature = "box_into_inner", issue = "80437")]
511+
#[inline]
512+
pub fn into_inner(boxed: Self) -> T {
513+
*boxed
514+
}
498515
}
499516

500517
impl<T> Box<[T]> {

0 commit comments

Comments
 (0)