Fix warnings about deprecated Error::description

This commit is contained in:
Sean McArthur
2020-01-29 15:15:58 -08:00
parent 5020ff0933
commit 74d02933a5
3 changed files with 24 additions and 50 deletions

View File

@@ -73,43 +73,33 @@ impl From<io::Error> for RecvError {
} }
} }
impl error::Error for RecvError { impl error::Error for RecvError {}
fn description(&self) -> &str {
use self::RecvError::*;
match *self {
Connection(ref reason) => reason.description(),
Stream { ref reason, .. } => reason.description(),
Io(ref e) => e.description(),
}
}
}
impl fmt::Display for RecvError { impl fmt::Display for RecvError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
use std::error::Error; use self::RecvError::*;
write!(fmt, "{}", self.description())
match *self {
Connection(ref reason) => reason.fmt(fmt),
Stream { ref reason, .. } => reason.fmt(fmt),
Io(ref e) => e.fmt(fmt),
}
} }
} }
// ===== impl SendError ===== // ===== impl SendError =====
impl error::Error for SendError { impl error::Error for SendError {}
fn description(&self) -> &str {
use self::SendError::*;
match *self {
User(ref e) => e.description(),
Connection(ref reason) => reason.description(),
Io(ref e) => e.description(),
}
}
}
impl fmt::Display for SendError { impl fmt::Display for SendError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
use std::error::Error; use self::SendError::*;
write!(fmt, "{}", self.description())
match *self {
User(ref e) => e.fmt(fmt),
Connection(ref reason) => reason.fmt(fmt),
Io(ref e) => e.fmt(fmt),
}
} }
} }
@@ -127,11 +117,13 @@ impl From<UserError> for SendError {
// ===== impl UserError ===== // ===== impl UserError =====
impl error::Error for UserError { impl error::Error for UserError {}
fn description(&self) -> &str {
impl fmt::Display for UserError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
use self::UserError::*; use self::UserError::*;
match *self { fmt.write_str(match *self {
InactiveStreamId => "inactive stream", InactiveStreamId => "inactive stream",
UnexpectedFrameType => "unexpected frame type", UnexpectedFrameType => "unexpected frame type",
PayloadTooBig => "payload too big", PayloadTooBig => "payload too big",
@@ -144,13 +136,6 @@ impl error::Error for UserError {
PollResetAfterSendResponse => "poll_reset after send_response is illegal", PollResetAfterSendResponse => "poll_reset after send_response is illegal",
SendPingWhilePending => "send_ping before received previous pong", SendPingWhilePending => "send_ping before received previous pong",
SendSettingsWhilePending => "sending SETTINGS before received previous ACK", SendSettingsWhilePending => "sending SETTINGS before received previous ACK",
} })
}
}
impl fmt::Display for UserError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
use std::error::Error;
write!(fmt, "{}", self.description())
} }
} }

View File

@@ -132,14 +132,4 @@ impl fmt::Display for Error {
} }
} }
impl error::Error for Error { impl error::Error for Error {}
fn description(&self) -> &str {
use self::Kind::*;
match self.kind {
Io(ref e) => error::Error::description(e),
Proto(ref reason) => reason.description(),
User(ref user) => user.description(),
}
}
}

View File

@@ -1,6 +1,5 @@
use futures::future::join; use futures::future::join;
use h2_support::prelude::*; use h2_support::prelude::*;
use std::error::Error;
#[tokio::test] #[tokio::test]
async fn read_none() { async fn read_none() {
@@ -209,7 +208,7 @@ async fn update_max_frame_len_at_rest() {
assert_eq!(codec.max_recv_frame_size(), 16_384); assert_eq!(codec.max_recv_frame_size(), 16_384);
assert_eq!( assert_eq!(
codec.next().await.unwrap().unwrap_err().description(), codec.next().await.unwrap().unwrap_err().to_string(),
"frame with invalid size" "frame with invalid size"
); );
} }