use std::fmt;
#[derive(Debug)]
pub enum ServerError {
Bind(std::io::Error),
Runtime(std::io::Error),
}
impl fmt::Display for ServerError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Bind(e) => write!(f, "failed to bind: {e}"),
Self::Runtime(e) => write!(f, "server runtime error: {e}"),
}
}
}
impl std::error::Error for ServerError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Bind(e) | Self::Runtime(e) => Some(e),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ServerConfigError {
InvalidPort(u16),
InvalidSampleInterval(u64),
}
impl fmt::Display for ServerConfigError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidPort(p) => write!(f, "port {p} is outside valid range 1..=65535"),
Self::InvalidSampleInterval(ms) => {
write!(
f,
"sample_interval_ms {ms} is outside valid range 250..=60000"
)
}
}
}
}
impl std::error::Error for ServerConfigError {}