Rust Ownership and Moves
Move owned text into one destination and use it there.
How it works
An owned value has a responsible owner, and many assignments or function calls transfer that ownership. String manages a heap allocation, so moving it does not create two independently writable owners of the same allocation. Small Copy values behave differently. The compiler rejects use of a moved String; clone explicitly creates a separate owned copy when that cost is justified.
Run the code
Reviewed with Rust 1.97.0, edition 2024, using the standard library only. Save the complete download as lesson-name.rs in a separate learning folder, compile with rustc --edition=2024 lesson-name.rs and run the resulting program (lesson-name.exe on Windows). Use the actual lesson filename. The final project includes complete Cargo package files; run cargo test --offline and cargo run --offline from that separate package folder. There is no Rust browser runner; PHP, Apache and MySQL are not needed.
This complete example was executed in the stated local review environment.
Example
fn main() {
let source = String::from("north tray");
let destination = source;
assert_eq!(destination, "north tray");
println!("Moved label: {destination}");
}
Expected result
Moved label: north tray
The original binding is intentionally not used after the move. The negative compiler checks in the review attempt that use and expect rejection. Ownership transfer is often the right design for handing a request or result to another component; it is not automatically a reason to clone every input.
Primary technical reference: Rust documentation.