File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -1225,6 +1225,20 @@ impl<T: ?Sized> Rc<T> {
1225
1225
///
1226
1226
/// // The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!
1227
1227
/// ```
1228
+ ///
1229
+ /// Convert a slice back into its original array:
1230
+ ///
1231
+ /// ```
1232
+ /// use std::rc::Rc;
1233
+ ///
1234
+ /// let x: Rc<[u32]> = Rc::new([1, 2, 3]);
1235
+ /// let x_ptr: *const [u32] = Rc::into_raw(x);
1236
+ ///
1237
+ /// unsafe {
1238
+ /// let x: Rc<[u32; 3]> = Rc::from_raw(x_ptr.cast::<[u32; 3]>())
1239
+ /// assert_eq!(x.as_ref(), &[1, 2, 3]);
1240
+ /// }
1241
+ /// ```
1228
1242
#[ inline]
1229
1243
#[ stable( feature = "rc_raw" , since = "1.17.0" ) ]
1230
1244
pub unsafe fn from_raw ( ptr : * const T ) -> Self {
Original file line number Diff line number Diff line change @@ -1371,6 +1371,20 @@ impl<T: ?Sized> Arc<T> {
1371
1371
///
1372
1372
/// // The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!
1373
1373
/// ```
1374
+ ///
1375
+ /// Convert a slice back into its original array:
1376
+ ///
1377
+ /// ```
1378
+ /// use std::sync::Arc;
1379
+ ///
1380
+ /// let x: Arc<[u32]> = Arc::new([1, 2, 3]);
1381
+ /// let x_ptr: *const [u32] = Arc::into_raw(x);
1382
+ ///
1383
+ /// unsafe {
1384
+ /// let x: Arc<[u32; 3]> = Arc::from_raw(x_ptr.cast::<[u32; 3]>())
1385
+ /// assert_eq!(x.as_ref(), &[1, 2, 3]);
1386
+ /// }
1387
+ /// ```
1374
1388
#[ inline]
1375
1389
#[ stable( feature = "rc_raw" , since = "1.17.0" ) ]
1376
1390
pub unsafe fn from_raw ( ptr : * const T ) -> Self {
You can’t perform that action at this time.
0 commit comments