xxxxxxxxxx
//Allocates a vector and a string
pub fn trim_whitespace(s: &str) -> String {
let words: Vec<_> = s.split_whitespace().collect();
words.join(" ")
}
//Only allocate a string
pub fn trim_whitespace(s: &str) -> String {
let mut result = String::with_capacity(s.len());
s.split_whitespace().for_each(|w| {
if !result.is_empty() {
result.push(' ');
}
result.push_str(w);
});
result
}