use core::error::Error;
use core::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct MetricTensorError(pub MetricTensorErrorEnum);
impl Error for MetricTensorError {}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum MetricTensorErrorEnum {
NonFinite { row: usize, col: usize },
Asymmetric { row: usize, col: usize },
Signature {
positive: usize,
negative: usize,
zero: usize,
},
}
impl MetricTensorError {
pub const fn new(kind: MetricTensorErrorEnum) -> Self {
Self(kind)
}
#[allow(non_snake_case)]
pub const fn NonFinite(row: usize, col: usize) -> Self {
Self(MetricTensorErrorEnum::NonFinite { row, col })
}
#[allow(non_snake_case)]
pub const fn Asymmetric(row: usize, col: usize) -> Self {
Self(MetricTensorErrorEnum::Asymmetric { row, col })
}
#[allow(non_snake_case)]
pub const fn Signature(positive: usize, negative: usize, zero: usize) -> Self {
Self(MetricTensorErrorEnum::Signature {
positive,
negative,
zero,
})
}
}
impl fmt::Display for MetricTensorError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.0 {
MetricTensorErrorEnum::NonFinite { row, col } => {
write!(f, "MetricTensorError: g[{row}][{col}] is not finite")
}
MetricTensorErrorEnum::Asymmetric { row, col } => write!(
f,
"MetricTensorError: the tensor is not symmetric: g[{row}][{col}] differs from \
g[{col}][{row}]"
),
MetricTensorErrorEnum::Signature {
positive,
negative,
zero,
} => write!(
f,
"MetricTensorError: the tensor is not of signature (−, +, +, +): {positive} \
positive, {negative} negative and {zero} zero eigenvalues"
),
}
}
}