Skip to content

Instantly share code, notes, and snippets.

@0ex-d
Last active September 29, 2025 14:52
Show Gist options
  • Select an option

  • Save 0ex-d/46e1b674aba07e27b47171e09fa4d18a to your computer and use it in GitHub Desktop.

Select an option

Save 0ex-d/46e1b674aba07e27b47171e09fa4d18a to your computer and use it in GitHub Desktop.
Copy & Clone : Various methods of keeping track of References (both single threaded(Rc) and multi-threaded (Arc,Mutex)
fn main(){
let p1 = 1_000;
let p2 = p1; // Copy
let v1 = Box::new(200); // stack pointer but value on the heap
let v2 = v1; // Clone & value moved
println!("p1: {:?}, p2: {:?}, v2: {:?}",p1,p2,v2);
}
use std::rc::Rc;
fn main(){
let p1 = Rc::new(5);
let p2 = Rc::clone(&p1); // ref only 'Clone'
let mut v2 = p1.clone(); // both ref & value Clone
v2 = Rc::new(10);
println!("p1: {:?}, p2: {:?}",p1,p2);
println!("p1: {:?}, v2: {:?}",p1,v2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment