Crate drc[][src]

This small library provides the Drc and Weak types. 'Drc' stands for 'Dynamically Reference Counted', and is the primary type that is used to interact with data stored within. It behaves identically to an Rc, except that it can be converted into an Arc, which is safe to pass across threads and then convert back into a Drc. This prevents unnecessary atomic operations when working on a single thread, without limiting the data to the thread.

Technical Details

Essentially, when an Arc is converted into a Drc, it is actually preserved in memory within a data structure located on the heap. Kept here are also a "local" strong and weak reference count. If the local strong reference count is zero, the stored Arc will be dropped, but at any other positive value, the Arc will be preserved. This effectively means that, within a thread, a Drc may be cloned and passed around indefinitely without any atomic operations occuring until the final Drc is dropped.

Drc's Weak functions similarly, but is a bit more complicated than Arc's Weak or Rc's Weak. Essentially, even when Drc's local strong reference count reaches zero, though the Arc will be dropped, a Drc can still be created if another Arc or set of Drcs exists by upgrading a Weak Drc.

Drc::new is simply a convenience method to create the Arc and place it within. It works exactly the same way as using from with an Arc.

Structs

Drc

A single-threaded reference-counting pointer with the special ability to be converted into an Arc. 'Drc' stands for 'Dynamically Reference Counted'.

Weak

Weak is a version of Drc that holds a non-owning reference to the managed value. The value is accessed by calling upgrade on the Weak pointer, which returns an Option < Drc<T> >.