refactor(error): remove PartialEq derives for error kind enums

Replaced the comparisons with `matches!`. This should reduce a bit of
code generation that isn't really needed.
This commit is contained in:
Sean McArthur
2021-06-07 15:50:49 -07:00
parent 8b71a67413
commit ea8b0cd86e

View File

@@ -17,11 +17,12 @@ struct ErrorImpl {
cause: Option<Cause>, cause: Option<Cause>,
} }
#[derive(Debug, PartialEq)] #[derive(Debug)]
pub(super) enum Kind { pub(super) enum Kind {
Parse(Parse), Parse(Parse),
User(User), User(User),
/// A message reached EOF, but is not complete. /// A message reached EOF, but is not complete.
#[allow(unused)]
IncompleteMessage, IncompleteMessage,
/// A connection received a message (or bytes) when not waiting for one. /// A connection received a message (or bytes) when not waiting for one.
#[cfg(feature = "http1")] #[cfg(feature = "http1")]
@@ -34,6 +35,7 @@ pub(super) enum Kind {
#[cfg(any(feature = "http1", feature = "http2"))] #[cfg(any(feature = "http1", feature = "http2"))]
Io, Io,
/// Error occurred while connecting. /// Error occurred while connecting.
#[allow(unused)]
Connect, Connect,
/// Error creating a TcpListener. /// Error creating a TcpListener.
#[cfg(all( #[cfg(all(
@@ -63,7 +65,7 @@ pub(super) enum Kind {
Http2, Http2,
} }
#[derive(Debug, PartialEq)] #[derive(Debug)]
pub(super) enum Parse { pub(super) enum Parse {
Method, Method,
Version, Version,
@@ -77,7 +79,7 @@ pub(super) enum Parse {
Internal, Internal,
} }
#[derive(Debug, PartialEq)] #[derive(Debug)]
pub(super) enum User { pub(super) enum User {
/// Error calling user's HttpBody::poll_data(). /// Error calling user's HttpBody::poll_data().
#[cfg(any(feature = "http1", feature = "http2"))] #[cfg(any(feature = "http1", feature = "http2"))]
@@ -152,27 +154,27 @@ impl Error {
/// Returns true if this was about a `Request` that was canceled. /// Returns true if this was about a `Request` that was canceled.
pub fn is_canceled(&self) -> bool { pub fn is_canceled(&self) -> bool {
self.inner.kind == Kind::Canceled matches!(self.inner.kind, Kind::Canceled)
} }
/// Returns true if a sender's channel is closed. /// Returns true if a sender's channel is closed.
pub fn is_closed(&self) -> bool { pub fn is_closed(&self) -> bool {
self.inner.kind == Kind::ChannelClosed matches!(self.inner.kind, Kind::ChannelClosed)
} }
/// Returns true if this was an error from `Connect`. /// Returns true if this was an error from `Connect`.
pub fn is_connect(&self) -> bool { pub fn is_connect(&self) -> bool {
self.inner.kind == Kind::Connect matches!(self.inner.kind, Kind::Connect)
} }
/// Returns true if the connection closed before a message could complete. /// Returns true if the connection closed before a message could complete.
pub fn is_incomplete_message(&self) -> bool { pub fn is_incomplete_message(&self) -> bool {
self.inner.kind == Kind::IncompleteMessage matches!(self.inner.kind, Kind::IncompleteMessage)
} }
/// Returns true if the body write was aborted. /// Returns true if the body write was aborted.
pub fn is_body_write_aborted(&self) -> bool { pub fn is_body_write_aborted(&self) -> bool {
self.inner.kind == Kind::BodyWriteAborted matches!(self.inner.kind, Kind::BodyWriteAborted)
} }
/// Returns true if the error was caused by a timeout. /// Returns true if the error was caused by a timeout.