Guest User

Untitled

a guest
May 24th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. enum List {
  2. Cons(i32, Rc<List>),
  3. Nil,
  4. }
  5.  
  6. use std::rc::Rc;
  7. use List::{Cons, Nil};
  8.  
  9. #[allow(unused_variables)]
  10. fn main() {
  11. let a = Rc::new(Cons(5, Rc::new(Cons(10, Rc::new(Nil)))));
  12. let b = Cons(3, Rc::clone(&a));
  13. let c = Cons(4, Rc::clone(&a));
  14. println!("The total references in a: {}", Rc::strong_count(&a));
  15. // println!("The total references in b: {}", Rc::strong_count(&b));
  16. // the above statement only works with Rc::new, but b is
  17. // b is a list
  18. {
  19. let d = Cons(10, Rc::clone(&a));
  20. println!("The total references for a: {}", Rc::strong_count(&a));
  21. }
  22. println!("The total references in a: {}", Rc::strong_count(&a));
  23.  
  24. }
Add Comment
Please, Sign In to add comment