Add Error::is_go_away() and Error::is_remote()

This commit is contained in:
Sean McArthur
2022-01-06 10:12:29 -08:00
parent c876dda6d0
commit 6336cc3d7b

View File

@@ -57,7 +57,7 @@ impl Error {
}
}
/// Returns the true if the error is an io::Error
/// Returns true if the error is an io::Error
pub fn is_io(&self) -> bool {
match self.kind {
Kind::Io(_) => true,
@@ -86,6 +86,21 @@ impl Error {
kind: Kind::Io(err),
}
}
/// Returns true if the error is from a `GOAWAY`.
pub fn is_go_away(&self) -> bool {
matches!(self.kind, Kind::GoAway(..))
}
/// Returns true if the error was received in a frame from the remote.
///
/// Such as from a received `RST_STREAM` or `GOAWAY` frame.
pub fn is_remote(&self) -> bool {
matches!(
self.kind,
Kind::GoAway(_, _, Initiator::Remote) | Kind::Reset(_, _, Initiator::Remote)
)
}
}
impl From<proto::Error> for Error {