Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created August 21, 2025 14:39
Show Gist options
  • Select an option

  • Save rust-play/33772aea60f9e02e3291e3396627b1c5 to your computer and use it in GitHub Desktop.

Select an option

Save rust-play/33772aea60f9e02e3291e3396627b1c5 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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