rust-itertools / itertools

Extra iterator adaptors, iterator methods, free functions, and macros.
https://docs.rs/itertools/
Apache License 2.0
2.62k stars 298 forks source link

FormatWith should implement fmt::Debug #929

Closed m-mueller678 closed 2 months ago

m-mueller678 commented 2 months ago

The value returned by format_with should implement std::fmt::Debug. Similar to the value returned by std::format_args, the Debug representation should be the same as the Display one. This allows using it in places like std::fmt::DebugStruct.

Philippe-Cholet commented 2 months ago

Similarly to https://doc.rust-lang.org/src/core/fmt/mod.rs.html#451 we could indeed delegate to Display:

impl<'a, I, F> fmt::Debug for FormatWith<'a, I, F>
where
    I: Iterator,
    F: FnMut(I::Item, &mut dyn FnMut(&dyn fmt::Display) -> fmt::Result) -> fmt::Result,
{
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt::Display::fmt(self, f)
    }
}

I don't see an issue with this, but I'm not familiar with those Format/FormatWith. @phimuemue @jswrenn Any objection?