@@ -230,6 +230,53 @@ pub const fn null<T>() -> *const T { 0 as *const T }
230
230
#[ rustc_promotable]
231
231
pub const fn null_mut < T > ( ) -> * mut T { 0 as * mut T }
232
232
233
+ #[ repr( C ) ]
234
+ pub ( crate ) union Repr < T > {
235
+ pub ( crate ) rust : * const [ T ] ,
236
+ rust_mut : * mut [ T ] ,
237
+ pub ( crate ) raw : FatPtr < T > ,
238
+ }
239
+
240
+ #[ repr( C ) ]
241
+ pub ( crate ) struct FatPtr < T > {
242
+ data : * const T ,
243
+ pub ( crate ) len : usize ,
244
+ }
245
+
246
+ /// Forms a slice from a pointer and a length.
247
+ ///
248
+ /// The `len` argument is the number of **elements**, not the number of bytes.
249
+ ///
250
+ /// # Examples
251
+ ///
252
+ /// ```rust
253
+ /// #![feature(slice_from_raw_parts)]
254
+ /// use std::ptr;
255
+ ///
256
+ /// // create a slice pointer when starting out with a pointer to the first element
257
+ /// let mut x = [5, 6, 7];
258
+ /// let ptr = &mut x[0] as *mut _;
259
+ /// let slice = ptr::slice_from_raw_parts_mut(ptr, 3);
260
+ /// assert_eq!(unsafe { &*slice }[2], 7);
261
+ /// ```
262
+ #[ inline]
263
+ #[ unstable( feature = "slice_from_raw_parts" , reason = "recently added" , issue = "36925" ) ]
264
+ pub fn slice_from_raw_parts < T > ( data : * const T , len : usize ) -> * const [ T ] {
265
+ unsafe { Repr { raw : FatPtr { data, len } } . rust }
266
+ }
267
+
268
+ /// Performs the same functionality as [`from_raw_parts`], except that a
269
+ /// mutable slice is returned.
270
+ ///
271
+ /// See the documentation of [`from_raw_parts`] for more details.
272
+ ///
273
+ /// [`from_raw_parts`]: ../../std/slice/fn.from_raw_parts.html
274
+ #[ inline]
275
+ #[ unstable( feature = "slice_from_raw_parts" , reason = "recently added" , issue = "36925" ) ]
276
+ pub fn slice_from_raw_parts_mut < T > ( data : * mut T , len : usize ) -> * mut [ T ] {
277
+ unsafe { Repr { raw : FatPtr { data, len } } . rust_mut }
278
+ }
279
+
233
280
/// Swaps the values at two mutable locations of the same type, without
234
281
/// deinitializing either.
235
282
///
0 commit comments