Concatenate strings in Rust using the format! macro or push_str method to join text efficiently.
Use the format! macro to concatenate strings without taking ownership, or the + operator if you own the first string.
let s1 = String::from("Hello");
let s2 = String::from("World");
let s3 = format!("{} {}", s1, s2);
println!("{s3}");
Alternatively, use push_str to append a string slice to an owned String:
let mut s = String::from("Hello");
s.push_str(" World");
println!("{s}");
String concatenation in Rust combines two or more pieces of text into one. You typically use the format! macro to join strings safely without losing the original data, similar to building a sentence from separate words. If you need to modify a string in place, you can append to it using methods like push_str.