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 @@ -433,6 +433,27 @@ impl<T: ?Sized> Rc<T> {
433
433
}
434
434
}
435
435
436
+ /// Consumes the `Rc`, returning the wrapped pointer as `NonNull<T>`.
437
+ ///
438
+ /// # Examples
439
+ ///
440
+ /// ```
441
+ /// #![feature(rc_into_raw_non_null)]
442
+ ///
443
+ /// use std::rc::Rc;
444
+ ///
445
+ /// let x = Rc::new(10);
446
+ /// let ptr = Rc::into_raw_non_null(x);
447
+ /// let deref = unsafe { *ptr.as_ref() };
448
+ /// assert_eq!(deref, 10);
449
+ /// ```
450
+ #[ unstable( feature = "rc_into_raw_non_null" , issue = "47336" ) ]
451
+ #[ inline]
452
+ pub fn into_raw_non_null ( this : Self ) -> NonNull < T > {
453
+ // safe because Rc guarantees its pointer is non-null
454
+ unsafe { NonNull :: new_unchecked ( Rc :: into_raw ( this) as * mut _ ) }
455
+ }
456
+
436
457
/// Creates a new [`Weak`][weak] pointer to this value.
437
458
///
438
459
/// [weak]: struct.Weak.html
Original file line number Diff line number Diff line change @@ -413,6 +413,27 @@ impl<T: ?Sized> Arc<T> {
413
413
}
414
414
}
415
415
416
+ /// Consumes the `Arc`, returning the wrapped pointer as `NonNull<T>`.
417
+ ///
418
+ /// # Examples
419
+ ///
420
+ /// ```
421
+ /// #![feature(rc_into_raw_non_null)]
422
+ ///
423
+ /// use std::sync::Arc;
424
+ ///
425
+ /// let x = Arc::new(10);
426
+ /// let ptr = Arc::into_raw_non_null(x);
427
+ /// let deref = unsafe { *ptr.as_ref() };
428
+ /// assert_eq!(deref, 10);
429
+ /// ```
430
+ #[ unstable( feature = "rc_into_raw_non_null" , issue = "47336" ) ]
431
+ #[ inline]
432
+ pub fn into_raw_non_null ( this : Self ) -> NonNull < T > {
433
+ // safe because Arc guarantees its pointer is non-null
434
+ unsafe { NonNull :: new_unchecked ( Arc :: into_raw ( this) as * mut _ ) }
435
+ }
436
+
416
437
/// Creates a new [`Weak`][weak] pointer to this value.
417
438
///
418
439
/// [weak]: struct.Weak.html
You can’t perform that action at this time.
0 commit comments