Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. enum List {
  2. Cons(i32, Rc<List>),
  3. Nil,
  4. }
  5.  
  6. use List::{Cons, Nil};
  7. use std::rc::Rc;
  8.  
  9. fn main() {
  10. let a = Rc::new(Cons(5, Rc::new(Cons(10, Rc::new(Nil)))));
  11. println!("count after creating a = {}", Rc::strong_count(&a));
  12. let b = Cons(3, Rc::clone(&a));
  13. println!("count after creating b = {}", Rc::strong_count(&a));
  14. {
  15. let c = Cons(4, Rc::clone(&a));
  16. println!("count after creating c = {}", Rc::strong_count(&a));
  17. }
  18. println!("count after c goes out of scope = {}", Rc::strong_count(&a));
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement