Error E0382

"use of moved value" — How to Fix

Fix Rust E0382 by cloning the value or passing a reference instead of moving ownership.

Error E0382 occurs because you are trying to use a variable after its ownership has been moved to another variable. To fix this, either clone the value if it implements the Clone trait, or pass a reference (&) instead of the value itself.

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

Alternatively, borrow the value:

let s1 = String::from("hello");
let s2 = &s1; // Borrows s1
println!("{} and {}", s1, s2);