ownership

String concatenation with +

Adding a borrowed suffix to an owned String consumes the left operand. Use push_str to mutate an existing buffer, or format! when assembling a message from several values. Expected stdout (not executed): Order ready " ready" Common mistake: Using first after it has moved.

Formal Syntax & Structure

rust syntaxrust
String + &str

Working Example

Example Snippetrust
fn main() {    let first = String::from("Order");    let second = String::from(" ready");    let combined = first + &second;    println!("{combined}");    println!("{second:?}");}
Rust Reference