Skip to content

Commit

Permalink
refactor(error): remove deprecated 'Error::description' method (#2092)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleades authored and seanmonstar committed Dec 30, 2019
1 parent fb90d30 commit 0f13719
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 35 deletions.
46 changes: 23 additions & 23 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions src/proto/h1/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 2 additions & 6 deletions src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =====

Expand Down

0 comments on commit 0f13719

Please sign in to comment.