use std::fmt;
#[derive(Debug, Clone, PartialEq)]
pub enum CovstreamError {
ZeroDimension,
WrongDimension { expected: usize, got: usize },
MalformedBatchInput { dimension: usize, len: usize },
InsufficientSamples { actual: usize },
NonFiniteInput,
OutputBufferTooSmall { expected: usize, got: usize },
}
impl fmt::Display for CovstreamError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CovstreamError::ZeroDimension => write!(f, "dimension must be greater than zero"),
CovstreamError::WrongDimension { expected, got } => {
write!(
f,
"wrong sample dimension: expected {}, got {}",
expected, got
)
}
CovstreamError::MalformedBatchInput { dimension, len } => {
write!(
f,
"batch input length must be a multiple of dimension: dimension {}, len {}",
dimension, len
)
}
CovstreamError::InsufficientSamples { actual } => {
write!(f, "insufficient samples: need at least 2, got {}", actual)
}
CovstreamError::NonFiniteInput => write!(f, "sample contains NaN or infinity"),
CovstreamError::OutputBufferTooSmall { expected, got } => {
write!(
f,
"output buffer too small: expected {}, got {}",
expected, got
)
}
}
}
}
impl std::error::Error for CovstreamError {}