Error

"value used here after move" — How to Fix

Fix the 'value used here after move' error by borrowing the variable with & or cloning it to create a new owned copy.

The error "value used here after move" occurs because you are trying to use a variable after its ownership has been transferred to another variable. To fix it, borrow the value using a reference (&) instead of moving it, or clone the value if you need a second owned copy.

let s1 = String::from("hello");
let s2 = &s1; // Borrow s1 instead of moving it
println!("{}", s1); // s1 is still valid
println!("{}", s2);

If you need two owned copies, use .clone():

let s1 = String::from("hello");
let s2 = s1.clone(); // Create a deep copy
println!("{}", s1);
println!("{}", s2);