]> git.proxmox.com Git - rustc.git/blob - src/doc/book/listings/ch15-smart-pointers/listing-15-19/src/main.rs
New upstream version 1.43.0+dfsg1
[rustc.git] / src / doc / book / listings / ch15-smart-pointers / listing-15-19 / src / main.rs
1 enum List {
2 Cons(i32, Rc<List>),
3 Nil,
4 }
5
6 use crate::List::{Cons, Nil};
7 use std::rc::Rc;
8
9 // ANCHOR: here
10 fn main() {
11 let a = Rc::new(Cons(5, Rc::new(Cons(10, Rc::new(Nil)))));
12 println!("count after creating a = {}", Rc::strong_count(&a));
13 let b = Cons(3, Rc::clone(&a));
14 println!("count after creating b = {}", Rc::strong_count(&a));
15 {
16 let c = Cons(4, Rc::clone(&a));
17 println!("count after creating c = {}", Rc::strong_count(&a));
18 }
19 println!("count after c goes out of scope = {}", Rc::strong_count(&a));
20 }
21 // ANCHOR_END: here