pub struct RcRcu<T> { /* private fields */ }
Expand description
A reference counted pointer that allows interior mutability
The RcRcu is functionally roughly equivalent to
Rc<RefCell<T>>
, except that reads (of the old value) may happen
while a write is taking place. Reads are actually slightly slower
than an Rc<RefCell<T>>
, so mostly you gaining ergonomics by
using this.
let x = rcu_clean::RcRcu::new(3);
let y: &usize = &(*x);
let z = x.clone();
*x.update() = 7; // Wow, we are mutating something we have borrowed!
assert_eq!(*y, 3); // the old reference is still valid.
assert_eq!(*x, 7); // but the pointer now points to the new value.
assert_eq!(*z, 7); // but the cloned pointer also points to the new value.