rcrefcell 1.0.7

Wrapper type for Rc<RefCell<A>>
Documentation
  • Coverage
  • 0%
    0 out of 6 items documented0 out of 5 items with examples
  • Size
  • Source code size: 4.95 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 287.20 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • floh1695 nicholasVilela

rcrefcell

Simple wrapper for Rc<RefCell<A>>

Example

#[derive(Debug, PartialEq)]
struct Data<A> {
  value: A
}

impl<A> Data<A> {
  fn new(value: A) -> Data<A> {
    Data {
      value,
    }
  }
}
  
let data: Data<i32> = Data::new(1);

let counter: RcCell<Data<i32>> = RcCell::new(data);
let counter_a: RcCell<Data<i32>> = counter.clone();
let counter_b: RcCell<Data<i32>> = counter.clone();

counter_a.update(|mut v| v.value += 1);
counter_b.borrow_mut().value *= 3;

assert_eq!(counter.borrow().value, 6);
assert_eq!(*counter_a.borrow(), *counter_b.borrow());