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 @@ -435,6 +435,27 @@ impl<T: ?Sized> Rc<T> {
435
435
}
436
436
}
437
437
438
+ /// Consumes the `Rc`, returning the wrapped pointer as `NonNull<T>`.
439
+ ///
440
+ /// # Examples
441
+ ///
442
+ /// ```
443
+ /// #![feature(rc_into_raw_non_null)]
444
+ ///
445
+ /// use std::rc::Rc;
446
+ ///
447
+ /// let x = Rc::new(10);
448
+ /// let ptr = Rc::into_raw_non_null(x);
449
+ /// let deref = unsafe { *ptr.as_ref() };
450
+ /// assert_eq!(deref, 10);
451
+ /// ```
452
+ #[ unstable( feature = "rc_into_raw_non_null" , issue = "47336" ) ]
453
+ #[ inline]
454
+ pub fn into_raw_non_null ( this : Self ) -> NonNull < T > {
455
+ // safe because Rc guarantees its pointer is non-null
456
+ unsafe { NonNull :: new_unchecked ( Rc :: into_raw ( this) as * mut _ ) }
457
+ }
458
+
438
459
/// Creates a new [`Weak`][weak] pointer to this value.
439
460
///
440
461
/// [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