How does ownership work with function parameters

Passing values moves ownership to the function, while passing references allows borrowing without transferring ownership.

Passing a value to a function moves ownership to the function, making the original variable unusable unless the type implements Copy. To retain ownership, pass a reference instead.

fn takes_ownership(s: String) { println!("{}", s); }
fn borrows(s: &String) { println!("{}", s); }

fn main() {
    let s = String::from("hello");
    takes_ownership(s); // s is moved, cannot use here
    borrows(&s);        // s is borrowed, can still use here
    println!("{}", s);  // OK
}