use std::fmt;
#[derive(Debug, Clone, PartialEq)]
pub enum Error {
Input(String),
Drift { eps: f64 },
NoAbsorber { eps: f64 },
LostProbability { units: usize },
Internal(String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Input(what) => write!(f, "invalid input: {what}"),
Error::Drift { eps } => write!(
f,
"the expected hits sum {eps:e} away from an integer, beyond the 1e-8 \
tolerance; they do not define a sample size"
),
Error::NoAbsorber { eps } => write!(
f,
"no unit can absorb the floating-point drift of {eps:e}: every \
fractional expected hit is too small"
),
Error::LostProbability { units } => write!(
f,
"{units} unit(s) with positive expected hits were left with no \
probability of selection"
),
Error::Internal(what) => write!(f, "internal accounting error: {what}"),
}
}
}
impl std::error::Error for Error {}