/// Represents HTTP/2 operation errors. /// /// `Error` covers error cases raised by protocol errors caused by the /// peer, I/O (transport) errors, and errors caused by the user of the library. /// /// If the error was caused by the remote peer, then it will contain a /// [`Reason`] which can be obtained with the [`reason`] function. /// /// [`Reason`]: struct.Reason.html /// [`reason`]: #method.reason #[derive(Debug)] pubstruct Error {
kind: Kind,
}
#[derive(Debug)] enum Kind { /// A RST_STREAM frame was received or sent.
Reset(StreamId, Reason, Initiator),
/// A GO_AWAY frame was received or sent.
GoAway(Bytes, Reason, Initiator),
/// The user created an error from a bare Reason.
Reason(Reason),
/// An error resulting from an invalid action taken by the user of this /// library.
User(UserError),
/// An `io::Error` occurred while trying to read or write.
Io(io::Error),
}
// ===== impl Error =====
impl Error { /// If the error was caused by the remote peer, the error reason. /// /// This is either an error received by the peer or caused by an invalid /// action taken by the peer (i.e. a protocol error). pubfn reason(&self) -> Option<Reason> { matchself.kind {
Kind::Reset(_, reason, _) | Kind::GoAway(_, reason, _) | Kind::Reason(reason) => {
Some(reason)
}
_ => None,
}
}
/// Returns true if the error is an io::Error pubfn is_io(&self) -> bool {
matches!(self.kind, Kind::Io(..))
}
/// Returns the error if the error is an io::Error pubfn get_io(&self) -> Option<&io::Error> { matchself.kind {
Kind::Io(ref e) => Some(e),
_ => None,
}
}
/// Returns the error if the error is an io::Error pubfn into_io(self) -> Option<io::Error> { matchself.kind {
Kind::Io(e) => Some(e),
_ => None,
}
}
/// Returns true if the error is from a `GOAWAY`. pubfn is_go_away(&self) -> bool {
matches!(self.kind, Kind::GoAway(..))
}
/// Returns true if the error is from a `RST_STREAM`. pubfn is_reset(&self) -> bool {
matches!(self.kind, Kind::Reset(..))
}
/// Returns true if the error was received in a frame from the remote. /// /// Such as from a received `RST_STREAM` or `GOAWAY` frame. pubfn is_remote(&self) -> bool {
matches!( self.kind,
Kind::GoAway(_, _, Initiator::Remote) | Kind::Reset(_, _, Initiator::Remote)
)
}
/// Returns true if the error was created by `h2`. /// /// Such as noticing some protocol error and sending a GOAWAY or RST_STREAM. pubfn is_library(&self) -> bool {
matches!( self.kind,
Kind::GoAway(_, _, Initiator::Library) | Kind::Reset(_, _, Initiator::Library)
)
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.