How to fix use of moved value error

Fix the 'use of moved value' error by passing a reference to the variable instead of moving ownership into the function.

The 'use of moved value' error occurs because Rust moved ownership of a variable to another location, making the original variable invalid for further use. To fix this, pass a reference to the variable instead of the variable itself by adding an ampersand (&) when calling the function and updating the function signature to accept a reference.

fn main() {
    let s1 = String::from("hello");
    let s2 = takes_reference(&s1); // Pass a reference
    println!("s1: {s1}"); // s1 is still valid here
}

fn takes_reference(some_string: &String) { // Accept a reference
    println!("{some_string}");
}

Alternatively, if you need to use the original variable after the function call, ensure the function does not take ownership by changing the parameter type from String to &String.