Implement alternate debug format {:#?}

This commit is contained in:
David Tolnay 2019-11-15 15:58:21 -08:00
parent d324d628f3
commit cba8b1fb47
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 8 additions and 1 deletions

View File

@ -102,7 +102,10 @@ where
E: Debug,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}\nCaused by: {:?}", self.context, self.error)
f.debug_struct("Error")
.field("context", &self.context.to_string())
.field("source", &self.error)
.finish()
}
}

View File

@ -678,6 +678,10 @@ impl ErrorImpl<()> {
}
fn debug(&self, f: &mut fmt::Formatter) -> fmt::Result {
if f.alternate() {
return Debug::fmt(self.error(), f);
}
writeln!(f, "{}", self.error())?;
let mut chain = self.chain().skip(1).enumerate().peekable();