-
-
Save rust-play/33772aea60f9e02e3291e3396627b1c5 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::rc::Rc; | |
| fn process_shared(data: Rc<String>, storage: &mut Vec<Rc<String>>) { | |
| storage.push(data.clone()); // Clones Rc, not String | |
| } | |
| fn main() { | |
| let shared = Rc::new("shared".to_string()); | |
| let mut storage = Vec::new(); | |
| while Rc::strong_count(&shared) < 10 { | |
| process_shared(shared.clone(), &mut storage); | |
| println!("Rc count: {}", Rc::strong_count(&shared)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment