use thiserror::Error;
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum ValidationReason {
#[error("missing required value")]
Missing,
#[error("out of range: {details}")]
OutOfRange {
details: &'static str,
},
#[error("bad shape: {details}")]
BadShape {
details: &'static str,
},
#[error("precondition violated: {details}")]
Precondition {
details: &'static str,
},
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TransportErrorClass {
Timeout,
Connect,
Redirect,
Decode,
Body,
Builder,
Request,
Status,
Upgrade,
ResponseTooLarge,
Other,
}
impl TransportErrorClass {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Timeout => "timeout",
Self::Connect => "connect",
Self::Redirect => "redirect",
Self::Decode => "decode",
Self::Body => "body",
Self::Builder => "builder",
Self::Request => "request",
Self::Status => "status",
Self::Upgrade => "upgrade",
Self::ResponseTooLarge => "response_too_large",
Self::Other => "other",
}
}
}
impl std::fmt::Display for TransportErrorClass {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}