File tree 1 file changed +23
-0
lines changed
1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -281,6 +281,29 @@ pub const fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut [T] {
281
281
unsafe { Repr { raw : FatPtr { data, len } } . rust_mut }
282
282
}
283
283
284
+ /// Get the length of a raw pointer to a slice without manifesting a reference.
285
+ ///
286
+ /// # Examples
287
+ ///
288
+ /// ```rust
289
+ /// #![feature(raw_slice_len)]
290
+ /// use std::ptr;
291
+ ///
292
+ /// let slice_ptr = 1_usize as *const [(); 64] as *const [()] as *const [u64];
293
+ ///
294
+ /// // This is unsound, as slice_ptr is not a pointer to a valid slice:
295
+ /// // assert_eq!((&*slice_ptr).len(), 64);
296
+ ///
297
+ /// // This is sound, as it does not create a reference:
298
+ /// assert_eq!(ptr::slice_len(slice_ptr), 64);
299
+ /// ```
300
+ #[ inline]
301
+ #[ unstable( feature = "raw_slice_len" , reason = "recently added" , issue = "none" ) ]
302
+ #[ rustc_const_unstable( feature = "const_raw_slice_len" , issue = "none" ) ]
303
+ pub const fn slice_len < T > ( data : * const [ T ] ) -> usize {
304
+ unsafe { Repr { rust : data } . raw . len }
305
+ }
306
+
284
307
/// Swaps the values at two mutable locations of the same type, without
285
308
/// deinitializing either.
286
309
///
You can’t perform that action at this time.
0 commit comments