Avatar ·

How to fix "use of moved value" error in Rust?

Hello! I started learning Rust and constantly encounter the "use of moved value" error. Here's a simple example that causes it:\n\n```rust\nfn main() {\n let s = String::from("hello");\n let t = s;\n println!("{}", s); // error: use of moved value: `s`\n}\n```\n\nI understand that Rust strictly tracks ownership, but I can't figure out how to properly pass data between variables and functions. For example, I want to write a function that takes a string, does something with it, and then I want to use that string again in main:\n\n```rust\nfn process(s: String) -> String {\n // some processing\n s\n}\n\nfn main() {\n let my_string = String::from("test");\n let result = process(my_string);\n println!("{}", my_string); // error again!\n}\n```\n\nWhy does this happen