use core::fmt;
#[derive(Debug, Clone, PartialEq)]
pub enum TableError {
ShapeMismatch {
expected_x: usize,
expected_y: usize,
actual_rows: usize,
actual_cols: usize,
},
TooFewSamples { axis: &'static str, len: usize },
NotMonotonic { axis: &'static str, at_index: usize },
OutOfRange {
axis: &'static str,
value: f64,
lo: f64,
hi: f64,
},
}
impl fmt::Display for TableError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TableError::ShapeMismatch {
expected_x,
expected_y,
actual_rows,
actual_cols,
} => write!(
f,
"table shape mismatch: expected {expected_y}×{expected_x}, got {actual_rows}×{actual_cols}"
),
TableError::TooFewSamples { axis, len } => {
write!(f, "{axis} axis has too few samples ({len}); need ≥ 2")
}
TableError::NotMonotonic { axis, at_index } => write!(
f,
"{axis} axis is not strictly monotonic at index {at_index}"
),
TableError::OutOfRange { axis, value, lo, hi } => write!(
f,
"{axis} value {value} is outside the sampled domain [{lo}, {hi}]"
),
}
}
}
impl std::error::Error for TableError {}