rcrefcell

Crates.iorcrefcell
lib.rsrcrefcell
version1.0.7
sourcesrc
created_at2022-05-31 02:20:30.051644
updated_at2022-07-16 02:33:09.219848
descriptionWrapper type for Rc>
homepage
repository
max_upload_size
id597217
size5,322
(nicholasVilela)

documentation

README

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());
Commit count: 0

cargo fmt