mirror of https://github.com/KaiserY/trpl-zh-cn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
525 B
25 lines
525 B
3 years ago
|
#[derive(Debug)]
|
||
|
enum List {
|
||
|
Cons(Rc<RefCell<i32>>, Rc<List>),
|
||
|
Nil,
|
||
|
}
|
||
|
|
||
|
use crate::List::{Cons, Nil};
|
||
|
use std::cell::RefCell;
|
||
|
use std::rc::Rc;
|
||
|
|
||
|
fn main() {
|
||
|
let value = Rc::new(RefCell::new(5));
|
||
|
|
||
|
let a = Rc::new(Cons(Rc::clone(&value), Rc::new(Nil)));
|
||
|
|
||
|
let b = Cons(Rc::new(RefCell::new(3)), Rc::clone(&a));
|
||
|
let c = Cons(Rc::new(RefCell::new(4)), Rc::clone(&a));
|
||
|
|
||
|
*value.borrow_mut() += 10;
|
||
|
|
||
|
println!("a after = {:?}", a);
|
||
|
println!("b after = {:?}", b);
|
||
|
println!("c after = {:?}", c);
|
||
|
}
|