2016-12-17 01:58:03 -08:00
|
|
|
use std::cell::{Cell, RefCell};
|
2016-04-06 04:20:35 -06:00
|
|
|
use std::rc::Rc;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
fn rc_cell() -> Rc<Cell<i32>> {
|
2016-03-21 04:18:30 -06:00
|
|
|
let r = Rc::new(Cell::new(42));
|
|
|
|
let x = r.get();
|
|
|
|
r.set(x + x);
|
2016-04-06 04:20:35 -06:00
|
|
|
r
|
2016-03-21 04:18:30 -06:00
|
|
|
}
|
|
|
|
|
2016-12-17 01:58:03 -08:00
|
|
|
fn rc_refcell() -> i32 {
|
|
|
|
let r = Rc::new(RefCell::new(42));
|
|
|
|
*r.borrow_mut() += 10;
|
|
|
|
let x = *r.borrow();
|
|
|
|
x
|
|
|
|
}
|
2016-03-21 18:53:39 -06:00
|
|
|
|
2016-04-06 04:20:35 -06:00
|
|
|
fn arc() -> Arc<i32> {
|
2016-03-21 04:18:30 -06:00
|
|
|
let a = Arc::new(42);
|
2016-04-06 04:20:35 -06:00
|
|
|
a
|
|
|
|
}
|
|
|
|
|
2016-03-21 04:37:28 -06:00
|
|
|
fn true_assert() {
|
|
|
|
assert_eq!(1, 1);
|
|
|
|
}
|
2016-04-22 10:34:14 +02:00
|
|
|
|
2016-04-22 14:38:46 +02:00
|
|
|
fn main() {
|
|
|
|
assert_eq!(*arc(), 42);
|
|
|
|
assert_eq!(rc_cell().get(), 84);
|
2016-12-17 01:58:03 -08:00
|
|
|
assert_eq!(rc_refcell(), 52);
|
2016-06-13 14:27:05 +02:00
|
|
|
true_assert();
|
2016-04-22 14:38:46 +02:00
|
|
|
}
|