#cell #arc #reference-counting #weak #weak-references #empty #sync

rcell

A Cell which can hold either an Arc or an Weak smartpointer or be empty

13 releases (6 stable)

2.0.0 Dec 8, 2022
2.0.0-pre0 Mar 10, 2022
1.1.3 Mar 3, 2022
0.5.0 Jan 24, 2022

#956 in Concurrency

22 downloads per month

MIT/Apache

10KB
171 lines

  • RCell, because all most its methods start with a "r"

A Wrapper for reference counted cell that can be Strong<T>, Weak<T> or Empty allowing one to retain values selectively.

To be used when one has to store a reference to some data but if this reference needs to keep it alive or not is to be determined at runtime.

The feature sync which is enabled by default selects std::sync::Arc<T> and std::sync::Weak<T> as rcell::Strong<T> and rcell::Weak<T>. When the sync feature is disabled then the non sync std::rc::Rc<T> and std::rc::Weak<T> are selected as rcell::Strong<T> and rcell::Weak<T>.


lib.rs:

Example:

use rcell::*;

// Our Type
#[derive(Debug, PartialEq)]
struct MyType<T>(T);

let my_rcell = RCell::new(MyType(100u8));
assert_eq!(*my_rcell.request().unwrap(), MyType(100));

No runtime deps

Features