A Rust `String` has a length—the number of valid elements—and a capacity—the number it can hold before becoming full. Appending past capacity requires reallocation; the standard library does not guarantee a particular growth strategy. section 2.4.1
Listing 2.18 Preallocating strings to aid performance
fn main() {
let mut x = String::with_capacity(10_000_000); #1
for i in 0..10_000_000 {
x.push('.');
}
println!("{}", x.len());
}
Preallocates capacity for a string that will receive ten million appended dots. section 2.4.1




