File tree 2 files changed +42
-0
lines changed
2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -826,6 +826,27 @@ impl<T> *const [T] {
826
826
// Only `std` can make this guarantee.
827
827
unsafe { Repr { rust : self } . raw } . len
828
828
}
829
+
830
+ /// Returns a raw pointer to the slice's buffer.
831
+ ///
832
+ /// This is equivalent to casting `self` to `*const T`, but more type-safe.
833
+ ///
834
+ /// # Examples
835
+ ///
836
+ /// ```rust
837
+ /// #![feature(slice_ptr_ptr)]
838
+ ///
839
+ /// use std::ptr;
840
+ ///
841
+ /// let slice: *const [i8] = ptr::slice_from_raw_parts(ptr::null(), 3);
842
+ /// assert_eq!(slice.as_ptr(), 0 as *const i8);
843
+ /// ```
844
+ #[ inline]
845
+ #[ unstable( feature = "slice_ptr_ptr" , issue = "none" ) ]
846
+ #[ rustc_const_unstable( feature = "const_slice_ptr_ptr" , issue = "none" ) ]
847
+ pub const fn as_ptr ( self ) -> * const T {
848
+ self as * const T
849
+ }
829
850
}
830
851
831
852
// Equality for pointers
Original file line number Diff line number Diff line change @@ -1028,6 +1028,27 @@ impl<T> *mut [T] {
1028
1028
// Only `std` can make this guarantee.
1029
1029
unsafe { Repr { rust_mut : self } . raw } . len
1030
1030
}
1031
+
1032
+ /// Returns a raw pointer to the slice's buffer.
1033
+ ///
1034
+ /// This is equivalent to casting `self` to `*mut T`, but more type-safe.
1035
+ ///
1036
+ /// # Examples
1037
+ ///
1038
+ /// ```rust
1039
+ /// #![feature(slice_ptr_ptr)]
1040
+ ///
1041
+ /// use std::ptr;
1042
+ ///
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);
1045
+ /// ```
1046
+ #[ inline]
1047
+ #[ unstable( feature = "slice_ptr_ptr" , issue = "none" ) ]
1048
+ #[ rustc_const_unstable( feature = "const_slice_ptr_ptr" , issue = "none" ) ]
1049
+ pub const fn as_ptr ( self ) -> * mut T {
1050
+ self as * mut T
1051
+ }
1031
1052
}
1032
1053
1033
1054
// Equality for pointers
You can’t perform that action at this time.
0 commit comments