diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2021-02-10 12:24:19 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-10 12:24:19 +0900 |
| commit | a28f2afbeb341a5d59730091af4d59e953f9e767 (patch) | |
| tree | 9b25065cd52e87a13b5e3861a6fe1b8b19f87af2 | |
| parent | bb06b13131d71eabfd7c4cecac9c10032715e9bd (diff) | |
| parent | ce7de07866b5b1a6e2c5458ecf7d3470f8492fd1 (diff) | |
| download | rust-a28f2afbeb341a5d59730091af4d59e953f9e767.tar.gz rust-a28f2afbeb341a5d59730091af4d59e953f9e767.zip | |
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`
| -rw-r--r-- | library/alloc/src/boxed.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index e87303749b4..354efdefc21 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -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]> { |
