- String::new
- push
- push_str
Create empty string and grow it using push and push_str
examples/strings/create-empty-string/src/main.rs
fn main() { let mut text = String::new(); println!("{text:?}"); text.push_str("Hello"); println!("{text:?}"); text.push(' '); println!("{text:?}"); text.push_str("World"); println!("{text:?}"); text.push('!'); println!("{text:?}"); }
"" "Hello" "Hello " "Hello World" "Hello World!"