use std::fmt;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Clone, PartialEq)]
pub enum Error {
InvalidParameter {
name: &'static str,
value: f64,
reason: &'static str,
},
InvalidProbability(f64),
InvalidMonth(u8),
Data(String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidParameter {
name,
value,
reason,
} => write!(f, "invalid parameter {name} = {value}: {reason}"),
Self::InvalidProbability(p) => write!(f, "probability {p} is not in [0, 1]"),
Self::InvalidMonth(m) => write!(f, "month {m} is not in 1 to 12"),
Self::Data(message) => write!(f, "invalid data: {message}"),
}
}
}
impl std::error::Error for Error {}