mirror of
https://github.com/gnu4cn/rust-lang-zh_CN.git
synced 2026-08-22 14:13:28 +08:00
Update Ch15
This commit is contained in:
@@ -18,14 +18,24 @@ impl List {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let a = Rc::new(Cons(5, RefCell::new(Rc::new(Nil))));
|
||||
let a = Rc::new(
|
||||
Cons(
|
||||
5,
|
||||
RefCell::new(Rc::new(Nil))
|
||||
)
|
||||
);
|
||||
|
||||
println! ("a 的初始 rc 计数 = {}", Rc::strong_count(&a));
|
||||
println! ("a 的下一条目 = {:?}", a.tail());
|
||||
|
||||
let b = Rc::new(Cons(10, RefCell::new(Rc::clone(&a))));
|
||||
let b = Rc::new(
|
||||
Cons(
|
||||
10,
|
||||
RefCell::new(Rc::clone(&a))
|
||||
)
|
||||
);
|
||||
|
||||
println! ("b 的创建后 a 的 rc 计数 = {}", Rc::strong_count(&a));
|
||||
println! ("创建 b 后 a 的 rc 计数 = {}", Rc::strong_count(&a));
|
||||
println! ("b 的初始 rc 计数 = {}", Rc::strong_count(&b));
|
||||
println! ("b 的下一条目 = {:?}", b.tail());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user