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
Unresolved Questions
- Do we also want
EmptyRc/EmptyArc?
- Are we concerned about confusion around the existing
is_unique methods? Could we add this functionality to Rc/Arc/ instead? (comment)
- Do we want consistency with Linux Kernel
UniqueRc? (comment)
Feature gate:
#![feature(unique_rc_arc)]This is a tracking issue for
UniqueRcandUniqueArc, 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 implementDerefMut). Weak pointers to the object can be made, but upgrading these will fail until it has been converted into a regular RC.Public API
Steps / History
UniqueRc: Addalloc::rc::UniqueRc#111849UniqueArcUnresolved Questions
EmptyRc/EmptyArc?is_uniquemethods? Could we add this functionality toRc/Arc/ instead? (comment)UniqueRc? (comment)Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩