How do I convert an Iterator<&str>Iterator<&str> to a StringString, interspersed with a constant string such as "\n"?
For instance, given:
let xs = vec!["first", "second", "third"];
let it = xs.iter();
One may produce a string s by collectcollecting into somea IterableVec<&str> and joinjoining the result:
let s = it
.map(|&x| x)
.collect::<Vec<&str>>()
.join("\n");
However, this unnecessarily allocates memorythis unnecessarily allocates memory for a Vec<&str>.
Is there a more direct method?