ownership
Rust Ownership in function arguments
A by-value String parameter takes ownership when called with an owned String. Use such a signature when a function should consume its input, not when it only needs temporary read access. Expected output (not executed): Sent: Ready Done Why: The parameter owns the string until the function finishes. Common mistake: Using message again in main after the call.
Formal Syntax & Structure
rust syntaxrust
fn consume(value: String) { ... }Working Example
Example Snippetrust
fn send(message: String) { println!("Sent: {message}");}fn main() { let message = String::from("Ready"); send(message); println!("Done");}