How to fix borrow of moved value

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

The error occurs because you are trying to use a variable after its ownership has been moved to another location. To fix it, pass a reference to the variable instead of the variable itself by adding an ampersand (&) before the variable name in the function call and updating the function signature to accept a reference.

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

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