1use std::fmt;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Debug, Clone, PartialEq)]
10pub enum Error {
11 InvalidParameter {
13 name: &'static str,
14 value: f64,
15 reason: &'static str,
16 },
17 InvalidProbability(f64),
19 InvalidMonth(u8),
21 Data(String),
25}
26
27impl fmt::Display for Error {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 match self {
30 Self::InvalidParameter {
31 name,
32 value,
33 reason,
34 } => write!(f, "invalid parameter {name} = {value}: {reason}"),
35 Self::InvalidProbability(p) => write!(f, "probability {p} is not in [0, 1]"),
36 Self::InvalidMonth(m) => write!(f, "month {m} is not in 1 to 12"),
37 Self::Data(message) => write!(f, "invalid data: {message}"),
38 }
39 }
40}
41
42impl std::error::Error for Error {}