use http::StatusCode;
use std::fmt;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum DroppedFailure {
Future(FutureDropped),
Body(BodyDropped),
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct FutureDropped;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct BodyDropped {
pub status: StatusCode,
}
impl fmt::Display for DroppedFailure {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
DroppedFailure::Future(_) => f.write_str("response future dropped before completion"),
DroppedFailure::Body(body) => {
write!(
f,
"response body dropped before end-of-stream (status: {})",
body.status
)
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn future_display() {
assert_eq!(
DroppedFailure::Future(FutureDropped).to_string(),
"response future dropped before completion",
);
}
#[test]
fn body_display_carries_status() {
assert_eq!(
DroppedFailure::Body(BodyDropped {
status: StatusCode::INTERNAL_SERVER_ERROR
})
.to_string(),
"response body dropped before end-of-stream (status: 500 Internal Server Error)",
);
}
}