Repository: rust-itertools/itertools (language: rust)

Issue:
FormatWith should implement fmt::Debug
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`.


Discussion / hints:
Similarly to https://doc.rust-lang.org/src/core/fmt/mod.rs.html#451 we could indeed delegate to `Display`:

```rust
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?

Fix patch:
diff --git a/src/format.rs b/src/format.rs
index c4cb65dcb..83382c5a5 100644
--- a/src/format.rs
+++ b/src/format.rs
@@ -71,6 +71,16 @@ where
     }
 }
 
+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)
+    }
+}
+
 impl<'a, I> Format<'a, I>
 where
     I: Iterator,


Test patch: