diff --git a/src/error.rs b/src/error.rs index 7cbcebce..e9da230a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -276,30 +276,7 @@ impl Error { Error::new(Kind::Http2).with(cause) } } -} -impl fmt::Debug for Error { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let mut f = f.debug_tuple("hyper::Error"); - f.field(&self.inner.kind); - if let Some(ref cause) = self.inner.cause { - f.field(cause); - } - f.finish() - } -} - -impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - if let Some(ref cause) = self.inner.cause { - write!(f, "{}: {}", self.description(), cause) - } else { - f.write_str(self.description()) - } - } -} - -impl StdError for Error { fn description(&self) -> &str { match self.inner.kind { Kind::Parse(Parse::Method) => "invalid HTTP method parsed", @@ -338,7 +315,30 @@ impl StdError for Error { Kind::User(User::ManualUpgrade) => "upgrade expected but low level API in use", } } +} +impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let mut f = f.debug_tuple("hyper::Error"); + f.field(&self.inner.kind); + if let Some(ref cause) = self.inner.cause { + f.field(cause); + } + f.finish() + } +} + +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + if let Some(ref cause) = self.inner.cause { + write!(f, "{}: {}", self.description(), cause) + } else { + f.write_str(self.description()) + } + } +} + +impl StdError for Error { fn source(&self) -> Option<&(dyn StdError + 'static)> { self.inner .cause diff --git a/src/proto/h1/decode.rs b/src/proto/h1/decode.rs index cdebd7a9..cbc7140d 100644 --- a/src/proto/h1/decode.rs +++ b/src/proto/h1/decode.rs @@ -371,15 +371,11 @@ struct IncompleteBody; impl fmt::Display for IncompleteBody { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(self.description()) + write!(f, "end of file before message length reached") } } -impl StdError for IncompleteBody { - fn description(&self) -> &str { - "end of file before message length reached" - } -} +impl StdError for IncompleteBody {} #[cfg(test)] mod tests { diff --git a/src/upgrade.rs b/src/upgrade.rs index 3b47cf68..55f39043 100644 --- a/src/upgrade.rs +++ b/src/upgrade.rs @@ -205,15 +205,11 @@ impl Pending { impl fmt::Display for UpgradeExpected { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(self.description()) + write!(f, "upgrade expected but not completed") } } -impl StdError for UpgradeExpected { - fn description(&self) -> &str { - "upgrade expected but not completed" - } -} +impl StdError for UpgradeExpected {} // ===== impl Io =====