about summary refs log tree commit diff
path: root/src/liballoc/sync.rs
diff options
context:
space:
mode:
authorDale Wijnand <dale.wijnand@gmail.com>2019-01-27 17:03:03 +0000
committerDale Wijnand <dale.wijnand@gmail.com>2019-01-28 22:24:26 +0000
commit1e577269da046b5e2b862830b72210c855fca123 (patch)
treef659508672ab1035c91209835e9ded3a610a8cec /src/liballoc/sync.rs
parent1484d0d123860dbd79804e9996f3fa5b6f4a6d58 (diff)
downloadrust-1e577269da046b5e2b862830b72210c855fca123.tar.gz
rust-1e577269da046b5e2b862830b72210c855fca123.zip
Introduce into_raw_non_null on Rc and Arc
Diffstat (limited to 'src/liballoc/sync.rs')
-rw-r--r--src/liballoc/sync.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs
index 390a0791650..5cffa93db11 100644
--- a/src/liballoc/sync.rs
+++ b/src/liballoc/sync.rs
@@ -413,6 +413,27 @@ impl<T: ?Sized> Arc<T> {
         }
     }
 
+    /// Consumes the `Arc`, returning the wrapped pointer as `NonNull<T>`.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// #![feature(rc_into_raw_non_null)]
+    ///
+    /// use std::sync::Arc;
+    ///
+    /// let x = Arc::new(10);
+    /// let ptr = Arc::into_raw_non_null(x);
+    /// let deref = unsafe { *ptr.as_ref() };
+    /// assert_eq!(deref, 10);
+    /// ```
+    #[unstable(feature = "rc_into_raw_non_null", issue = "47336")]
+    #[inline]
+    pub fn into_raw_non_null(this: Self) -> NonNull<T> {
+        // safe because Arc guarantees its pointer is non-null
+        unsafe { NonNull::new_unchecked(Arc::into_raw(this) as *mut _) }
+    }
+
     /// Creates a new [`Weak`][weak] pointer to this value.
     ///
     /// [weak]: struct.Weak.html