Collections
Strings
Building Text
String is a growable, owned text buffer. push_str adds text and push adds one character.
Program
Play the program to build a word one piece at a time.
strings.rs
fn main() {
let mut sentence = String::new();
sentence.push_str("Rust");
sentence.push('!');
println!("{sentence} ({})", sentence.len());
}
String::new
`String::new()` starts an empty owned string.
push_str
`push_str` appends a string slice.
push
`push` appends a single `char`.