From a784729cde2f558bba91984eadf0f152b8a9d288 Mon Sep 17 00:00:00 2001 From: Tim Diekmann Date: Thu, 6 Aug 2020 11:45:54 +0200 Subject: [PATCH] Add `as_mut_ptr` to `NonNull<[T]>` --- library/core/src/ptr/non_null.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 9f843a57099..5163b2d9d56 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -224,6 +224,24 @@ impl NonNull<[T]> { unsafe { NonNull::new_unchecked(self.as_ptr().as_mut_ptr()) } } + /// Returns a raw pointer to the slice's buffer. + /// + /// # Examples + /// + /// ```rust + /// #![feature(slice_ptr_get, nonnull_slice_from_raw_parts)] + /// use std::ptr::NonNull; + /// + /// let slice: NonNull<[i8]> = NonNull::slice_from_raw_parts(NonNull::dangling(), 3); + /// assert_eq!(slice.as_mut_ptr(), 1 as *mut i8); + /// ``` + #[inline] + #[unstable(feature = "slice_ptr_get", issue = "74265")] + #[rustc_const_unstable(feature = "slice_ptr_get", issue = "74265")] + pub const fn as_mut_ptr(self) -> *mut T { + self.as_non_null_ptr().as_ptr() + } + /// Returns a raw pointer to an element or subslice, without doing bounds /// checking. ///