refactor(error): remove deprecated 'Error::description' method (#2092)

This commit is contained in:
danieleades
2019-12-30 17:55:08 +00:00
committed by Sean McArthur
parent fb90d30c02
commit 0f13719873
3 changed files with 27 additions and 35 deletions

View File

@@ -276,30 +276,7 @@ impl Error {
Error::new(Kind::Http2).with(cause) 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 { fn description(&self) -> &str {
match self.inner.kind { match self.inner.kind {
Kind::Parse(Parse::Method) => "invalid HTTP method parsed", 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", 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)> { fn source(&self) -> Option<&(dyn StdError + 'static)> {
self.inner self.inner
.cause .cause

View File

@@ -371,15 +371,11 @@ struct IncompleteBody;
impl fmt::Display for IncompleteBody { impl fmt::Display for IncompleteBody {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 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 { impl StdError for IncompleteBody {}
fn description(&self) -> &str {
"end of file before message length reached"
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

View File

@@ -205,15 +205,11 @@ impl Pending {
impl fmt::Display for UpgradeExpected { impl fmt::Display for UpgradeExpected {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 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 { impl StdError for UpgradeExpected {}
fn description(&self) -> &str {
"upgrade expected but not completed"
}
}
// ===== impl Io ===== // ===== impl Io =====