2016-09-27 10:02:04 -05:00
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::rc::Rc;
|
|
|
|
|
|
|
|
fn rc_refcell() -> i32 {
|
|
|
|
let r = Rc::new(RefCell::new(42));
|
|
|
|
*r.borrow_mut() += 10;
|
|
|
|
let x = *r.borrow();
|
|
|
|
x
|
|
|
|
}
|
|
|
|
|
2017-06-12 17:22:58 -05:00
|
|
|
fn rc_raw() {
|
|
|
|
let r = Rc::new(0);
|
|
|
|
let r2 = Rc::into_raw(r.clone());
|
|
|
|
let r2 = unsafe { Rc::from_raw(r2) };
|
|
|
|
assert!(Rc::ptr_eq(&r, &r2));
|
|
|
|
drop(r);
|
|
|
|
assert!(Rc::try_unwrap(r2).is_ok());
|
|
|
|
}
|
|
|
|
|
2016-09-27 10:02:04 -05:00
|
|
|
fn main() {
|
|
|
|
rc_refcell();
|
2017-06-12 17:22:58 -05:00
|
|
|
rc_raw();
|
2016-09-27 10:02:04 -05:00
|
|
|
}
|