Skip to content

Instantly share code, notes, and snippets.

@0ex-d
Created January 6, 2025 02:22
Show Gist options
  • Save 0ex-d/46e1b674aba07e27b47171e09fa4d18a to your computer and use it in GitHub Desktop.
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
}
use std::rc::Rc;
fn main(){
let p1 = Rc::new(5);
let p2 = Rc::clone(&p1); // ref only 'Clone'
let v1 = Rc::new(5);
let v2 = v1.clone(); // both ref & value Clone
println!("p1: {:?}, p2: {:?}",p1,p2);
println!("v1: {:?}, v2: {:?}",v1,v2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment