Skip to content
Myr

Implement alternate display format {:#}

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Tolnay · committed by David Tolnay · parent cba8b1f · Browse files · 1 file+29 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+29 added−14 removed

  • other:+29 added−14 removed

1 file+29 added−14 removed

modified:src/error.rs+29 added-14 removed
416 unmodified lines
417 self.inner.error_mut()418 }419}420421impl Debug for Error {421impl Display for Error {422 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {423 self.inner.debug(formatter)423 self.inner.display(formatter)424 }425}426427impl Display for Error {428 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {429 write!(f, "{}", self.inner.error())427impl Debug for Error {428 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {429 self.inner.debug(formatter)430 }431}432433unsafe impl Send for Error {}
242 unmodified lines
676 next: Some(self.error()),677 }678 }679680 fn debug(&self, f: &mut fmt::Formatter) -> fmt::Result {681 if f.alternate() {682 return Debug::fmt(self.error(), f);683 }680 fn print_chain(&self, f: &mut fmt::Formatter) -> fmt::Result {681 write!(f, "{}", self.error())?;682685 writeln!(f, "{}", self.error())?;686683 let mut chain = self.chain().skip(1).enumerate().peekable();684 if let Some((n, error)) = chain.next() {689 write!(f, "\nCaused by:\n ")?;685 write!(f, "\n\nCaused by:\n ")?;686 if chain.peek().is_some() {687 write!(f, "{}: ", n)?;688 }693 writeln!(f, "{}", error)?;689 write!(f, "{}", error)?;690 for (n, error) in chain {695 writeln!(f, " {}: {}", n, error)?;691 write!(f, "\n {}: {}", n, error)?;692 }693 }694695 Ok(())696 }697698 fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {699 if f.alternate() {700 self.print_chain(f)701 } else {702 write!(f, "{}", self.error())703 }704 }705706 fn debug(&self, f: &mut fmt::Formatter) -> fmt::Result {707 if f.alternate() {708 return Debug::fmt(self.error(), f);709 }710711 self.print_chain(f)?;712 writeln!(f)?;713714 #[cfg(backtrace)]715 {716 use std::backtrace::BacktraceStatus;717
82 unmodified lines