MCPcopy Create free account
hub / github.com/bedroombuilds/python2rust / main

Function main

10_smart_pointers/rust/smartpointers.rs:11–32  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9}
10
11fn main() -> Result<()> {
12 let a = Box::new(5);
13 println!("deref of box {:?} yields {}", a, *a);
14 let mut l = List {
15 next: None,
16 value: 1,
17 };
18 l.next = Some(Box::new(List {
19 next: None,
20 value: 2,
21 }));
22 println!("list value {}", l.value);
23
24 let b = Rc::new(*a);
25 let _c = Rc::clone(&b); // increase reference count (cheap)
26 println!("{} refcount: {}", &b, Rc::strong_count(&b));
27 // if b is not a Rc type this is potentially deep-copying (expensive)
28 // avoid this notation when doing refcount clones
29 let _d = b.clone();
30 println!("{} refcount: {}", &b, Rc::strong_count(&b));
31 Ok(())
32}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected