use std::fmt;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ConfigError {
pub field: &'static str,
pub reason: &'static str,
}
impl fmt::Display for ConfigError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}: {}", self.field, self.reason)
}
}
impl std::error::Error for ConfigError {}
impl crate::Config {
pub fn validate(&self) -> Result<(), ConfigError> {
if self.retry_delay.is_zero() {
return Err(ConfigError {
field: "retry_delay",
reason: "must be positive",
});
}
if self.max_retry_delay < self.retry_delay {
return Err(ConfigError {
field: "max_retry_delay",
reason: "must be at least retry_delay",
});
}
Ok(())
}
}
impl crate::RetryPolicy {
pub fn validate(&self) -> Result<(), ConfigError> {
Ok(())
}
}