4 releases

0.1.3 Sep 1, 2021
0.1.2 Aug 30, 2021
0.1.1 Aug 27, 2021
0.1.0 Aug 27, 2021

#638 in Memory management

Download history 32/week @ 2024-03-07 22/week @ 2024-03-14 2/week @ 2024-03-21 10/week @ 2024-03-28 15/week @ 2024-04-04 6/week @ 2024-04-11 5/week @ 2024-04-18 22/week @ 2024-04-25 5/week @ 2024-05-02 2/week @ 2024-05-09 8/week @ 2024-05-16 26/week @ 2024-05-23 30/week @ 2024-05-30 15/week @ 2024-06-06 7/week @ 2024-06-13 2/week @ 2024-06-20

56 downloads per month
Used in 2 crates (via l1x-wasm-llvmir)

MIT license

17KB
222 lines

RcCell

A convenient wrapper for Rc<RefCell<T>>> and Weak<RefCell<T>>>.

The RcCell library adds two new structs:

  • RcCell<T>: a wrapper for Rc<RefCell<T>>.
  • WeakCell<T>: a wrapper for Weak<RefCell<T>>.

This library extends the rc-cell library.

Example

use rccell::{RcCell, WeakCell};

let a = RcCell::new(1);     // a is a RcCell that wraps an Rc<RefCell<i32>>
let b = a.clone();          // You can create multiple RcCells pointing to the same data.

let mut c = a.borrow_mut();  // You can use borrow and borrow_mut methods as if  RcCells were RefCells
*c = 2;
// let mut d = b.borrow_mut()   You cannot create two RefMuts for the same RcCell.
drop(c);

assert!(a.try_borrow().is_ok());  // You can use try_borrow and try_borrow_mut to avoid panicking
// let d = a.unwrap()  You can use unwrap to get the inner value (if there is only one RcCell)
assert!(a.try_unwrap().is_err());  // You can use try_unwrap to avoid panicking

let d: WeakCell<i32> = b.downgrade();  // Use downgrade to create a WeakCell pointing to the same data
assert!(d.upgrade().is_some());  // Use the upgrade method to get a RcCell pointing to the same data as the WeakCell.

No runtime deps