Tracking Issue for UniqueRc/UniqueArc · Issue #112566 · rust-lang/rust (original) (raw)

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

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html