use std::fmt;
use std::time::Duration;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Outcome {
Response {
status: u16,
},
Error(ErrorKind),
}
impl Outcome {
#[must_use]
pub fn is_failure(&self) -> bool {
match self {
Self::Response { status } => *status >= 400,
Self::Error(_) => true,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ErrorKind {
Timeout,
Connect,
Io,
Other,
}
impl ErrorKind {
#[must_use]
pub fn as_str(self) -> &'static str {
match self {
Self::Timeout => "timeout",
Self::Connect => "connect",
Self::Io => "io",
Self::Other => "other",
}
}
}
impl fmt::Display for ErrorKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Sample {
pub latency: Duration,
pub send_lag: Duration,
pub outcome: Outcome,
}