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

Function main

10_smart_pointers/rust/rc.rs:3–30  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1use std::rc::Rc;
2
3fn main() {
4 let rc_examples = "Rc examples".to_string();
5 // new scope
6 {
7 println!("--- rc_a is created ---");
8
9 let rc_a: Rc<String> = Rc::new(rc_examples);
10 println!("Reference Count of rc_a: {}", Rc::strong_count(&rc_a));
11
12 // one more scope
13 {
14 let rc_b: Rc<String> = Rc::clone(&rc_a);
15 println!("Ref Count of rc_b: {}", Rc::strong_count(&rc_b));
16 println!("Ref Count of rc_a: {}", Rc::strong_count(&rc_a));
17
18 // Two `Rc`s are equal if their inner values are equal
19 println!("rc_a and rc_b are equal: {}", rc_a.eq(&rc_b));
20
21 // We can use methods of a value directly
22 println!("Length of the value inside rc_a: {}", rc_a.len());
23 println!("Value of rc_b: {}", rc_b);
24 }
25
26 println!("Reference Count of rc_a: {}", Rc::strong_count(&rc_a));
27
28 println!("--- rc_a is dropped out of scope ---");
29 }
30}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected