This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change 9393#![ feature( const_slice_ptr_len) ]
9494#![ feature( const_type_name) ]
9595#![ feature( const_likely) ]
96+ #![ feature( const_slice_ptr_ptr) ]
9697#![ feature( custom_inner_attributes) ]
9798#![ feature( decl_macro) ]
9899#![ feature( doc_cfg) ]
Original file line number Diff line number Diff line change @@ -1041,12 +1041,12 @@ impl<T> *mut [T] {
10411041 /// use std::ptr;
10421042 ///
10431043 /// let slice: *mut [i8] = ptr::slice_from_raw_parts_mut(ptr::null_mut(), 3);
1044- /// assert_eq!(slice.as_ptr (), 0 as *mut i8);
1044+ /// assert_eq!(slice.as_mut_ptr (), 0 as *mut i8);
10451045 /// ```
10461046 #[ inline]
10471047 #[ unstable( feature = "slice_ptr_ptr" , issue = "none" ) ]
10481048 #[ rustc_const_unstable( feature = "const_slice_ptr_ptr" , issue = "none" ) ]
1049- pub const fn as_ptr ( self ) -> * mut T {
1049+ pub const fn as_mut_ptr ( self ) -> * mut T {
10501050 self as * mut T
10511051 }
10521052}
Original file line number Diff line number Diff line change @@ -204,6 +204,26 @@ impl<T> NonNull<[T]> {
204204 pub const fn len ( self ) -> usize {
205205 self . as_ptr ( ) . len ( )
206206 }
207+
208+ /// Returns a non-null pointer to the slice's buffer.
209+ ///
210+ /// # Examples
211+ ///
212+ /// ```rust
213+ /// #![feature(slice_ptr_ptr, nonnull_slice_from_raw_parts)]
214+ ///
215+ /// use std::ptr::NonNull;
216+ ///
217+ /// let slice: NonNull<[i8]> = NonNull::slice_from_raw_parts(NonNull::dangling(), 3);
218+ /// assert_eq!(slice.as_non_null_ptr(), NonNull::new(1 as *mut i8).unwrap());
219+ /// ```
220+ #[ inline]
221+ #[ unstable( feature = "slice_ptr_ptr" , issue = "none" ) ]
222+ #[ rustc_const_unstable( feature = "const_slice_ptr_ptr" , issue = "none" ) ]
223+ pub const fn as_non_null_ptr ( self ) -> NonNull < T > {
224+ // SAFETY: We know `self` is non-null.
225+ unsafe { NonNull :: new_unchecked ( self . as_ptr ( ) . as_mut_ptr ( ) ) }
226+ }
207227}
208228
209229#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
You can’t perform that action at this time.
0 commit comments