fn print_message(msg: String) { println!("{}", msg); } fn main() { let s = String::from("hello"); print_message(s); // ownership of `s` moves into `print_message` println!("{}", s); // error[E0382]: borrow of moved value: `s` }
Write a short Rust example that triggers E0382 (use of moved value): a String is passed to a function and then used again. Explain why the compiler objects, then fix the same code in three separate ways: by borrowing, by cloning and by returning the value.
