Skip to content

Commit a28f2af

Browse files
authored
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`
2 parents bb06b13 + ce7de07 commit a28f2af

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
@@ -509,6 +509,23 @@ impl<T, A: Allocator> Box<T, A> {
509509
let (raw, alloc) = Box::into_raw_with_allocator(boxed);
510510
unsafe { Box::from_raw_in(raw as *mut [T; 1], alloc) }
511511
}
512+
513+
/// Consumes the `Box`, returning the wrapped value.
514+
///
515+
/// # Examples
516+
///
517+
/// ```
518+
/// #![feature(box_into_inner)]
519+
///
520+
/// let c = Box::new(5);
521+
///
522+
/// assert_eq!(Box::into_inner(c), 5);
523+
/// ```
524+
#[unstable(feature = "box_into_inner", issue = "80437")]
525+
#[inline]
526+
pub fn into_inner(boxed: Self) -> T {
527+
*boxed
528+
}
512529
}
513530

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

0 commit comments

Comments
 (0)