1use std::fmt;
2
3#[derive(Clone, Debug)]
4pub enum Error<const D: usize> {
6 InvalidBoxSize { value: f64, box_size: Vec<f64> },
10 InvalidRmin(f64),
15 GenCoordOutOfBounds([f64; D]),
19 InvalidActiveList,
23}
24
25impl<const D: usize> fmt::Display for Error<D> {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 match self {
28 Error::InvalidBoxSize { value, box_size } => write!(
29 f,
30 "invalid value '{}' in input box size '{:?}': must be a positive number",
31 value, box_size
32 ),
33 Error::InvalidRmin(rmin) => write!(
34 f,
35 "invalid value for input `rmin` ({}): must be a positive number",
36 rmin
37 ),
38 Error::GenCoordOutOfBounds(coord) => write!(
39 f,
40 "generated and used an out-of-box coordinate ({:?}): this should not happen, please file an issue",
41 coord
42 ),
43 Error::InvalidActiveList => write!(
44 f,
45 "active list contains an index which does not lead to a sample: this should not happen, please file an issue"
46 ),
47 }
48 }
49}
50
51impl<const D: usize> std::error::Error for Error<D> {}
52
53#[cfg(test)]
54impl<const D: usize> Error<D> {
55 pub(crate) fn is_invalid_box_size(&self) -> bool {
56 match self {
57 Error::InvalidBoxSize { .. } => true,
58 _ => false,
59 }
60 }
61
62 pub(crate) fn is_invalid_rmin(&self) -> bool {
63 match self {
64 Error::InvalidRmin(_) => true,
65 _ => false,
66 }
67 }
68}