Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum List {
- Cons(i32, Rc<List>),
- Nil,
- }
- use std::rc::Rc;
- use List::{Cons, Nil};
- #[allow(unused_variables)]
- fn main() {
- let a = Rc::new(Cons(5, Rc::new(Cons(10, Rc::new(Nil)))));
- let b = Cons(3, Rc::clone(&a));
- let c = Cons(4, Rc::clone(&a));
- println!("The total references in a: {}", Rc::strong_count(&a));
- // println!("The total references in b: {}", Rc::strong_count(&b));
- // the above statement only works with Rc::new, but b is
- // b is a list
- {
- let d = Cons(10, Rc::clone(&a));
- println!("The total references for a: {}", Rc::strong_count(&a));
- }
- println!("The total references in a: {}", Rc::strong_count(&a));
- }
Add Comment
Please, Sign In to add comment