Ownership
let x = 5;
let y = x;
println!("x = {x}, y = {y}"); //works fine, cuz on stack so fast
//different cuz on heap
let s1 = String::from("hello");
let s2 = s1;
println!("{s1}, world!"); //invalid bc since strings stored as ptr, rust auto declares s1 invalid
//instead
let s1 = String::from("hello");
let s2 = s1.clone();
println!("s1 = {s1}, s2 = {s2}");References And Borrowing
Last updated