use std::fmt;
#[derive(Clone, Debug)]
pub enum Error<const D: usize> {
InvalidBoxSize { value: f64, box_size: Vec<f64> },
InvalidRmin(f64),
GenCoordOutOfBounds([f64; D]),
InvalidActiveList,
}
impl<const D: usize> fmt::Display for Error<D> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::InvalidBoxSize { value, box_size } => write!(
f,
"invalid value '{}' in input box size '{:?}': must be a positive number",
value, box_size
),
Error::InvalidRmin(rmin) => write!(
f,
"invalid value for input `rmin` ({}): must be a positive number",
rmin
),
Error::GenCoordOutOfBounds(coord) => write!(
f,
"generated and used an out-of-box coordinate ({:?}): this should not happen, please file an issue",
coord
),
Error::InvalidActiveList => write!(
f,
"active list contains an index which does not lead to a sample: this should not happen, please file an issue"
),
}
}
}
impl<const D: usize> std::error::Error for Error<D> {}
#[cfg(test)]
impl<const D: usize> Error<D> {
pub(crate) fn is_invalid_box_size(&self) -> bool {
match self {
Error::InvalidBoxSize { .. } => true,
_ => false,
}
}
pub(crate) fn is_invalid_rmin(&self) -> bool {
match self {
Error::InvalidRmin(_) => true,
_ => false,
}
}
}