Open
Description
Feature gate: #![feature(unique_rc_arc)]
This is a tracking issue for UniqueRc
and UniqueArc
, as discussed in rust-lang/libs-team#90.
This feature supports creating cyclic data structures by creating an RC that is guaranteed to be uniquely owned. The uniquely owned RC can then be converted to a regular RC. While uniquely owned, we can freely modify the contents of the UniqueRc
/UniqueArc
(i.e. they implement DerefMut
). Weak pointers to the object can be made, but upgrading these will fail until it has been converted into a regular RC.
Public API
let rc = UniqueRc::new(42);
let weak = UniqueRc::downgrade(&rc);
assert!(weak.upgrade().is_none());
let _rc = UniqueRc::into_rc(rc);
assert_eq!(*weak.upgrade().unwrap(), 42);
Steps / History
- Implementation:
-
UniqueRc
: Addalloc::rc::UniqueRc
#111849 -
UniqueArc
-
- Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- Do we also want
EmptyRc
/EmptyArc
? - Are we concerned about confusion around the existing
is_unique
methods? Could we add this functionality toRc
/Arc
/ instead? (comment) - Do we want consistency with Linux Kernel
UniqueRc
? (comment)