Is there any reason why the language doesn't implement something like this?
impl <T: Iterator<Item=char>> Display for T {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
for next_char in self {
f.write_char(next_char)?;
}
Ok(())
}
}
It would save a fair bit of memory on intermediate buffers such as collect::<String>() produces. A good example of a use case is converting borrowed byte slices/iterators to byte-slice literals:
Display takes &self and requires fmt to be able to be called more than once. However IntoIterator::into_iter consumes self and so can be called only once.