File tree 3 files changed +23
-2
lines changed
3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change 93
93
#![ feature( const_slice_ptr_len) ]
94
94
#![ feature( const_type_name) ]
95
95
#![ feature( const_likely) ]
96
+ #![ feature( const_slice_ptr_ptr) ]
96
97
#![ feature( custom_inner_attributes) ]
97
98
#![ feature( decl_macro) ]
98
99
#![ feature( doc_cfg) ]
Original file line number Diff line number Diff line change @@ -1041,12 +1041,12 @@ impl<T> *mut [T] {
1041
1041
/// use std::ptr;
1042
1042
///
1043
1043
/// 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);
1045
1045
/// ```
1046
1046
#[ inline]
1047
1047
#[ unstable( feature = "slice_ptr_ptr" , issue = "none" ) ]
1048
1048
#[ 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 {
1050
1050
self as * mut T
1051
1051
}
1052
1052
}
Original file line number Diff line number Diff line change @@ -204,6 +204,26 @@ impl<T> NonNull<[T]> {
204
204
pub const fn len ( self ) -> usize {
205
205
self . as_ptr ( ) . len ( )
206
206
}
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
+ }
207
227
}
208
228
209
229
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
You can’t perform that action at this time.
0 commit comments