use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
UnequalChannels {
mark: &'static str,
lengths: (usize, usize),
},
NonRectangular {
mark: &'static str,
shape: (usize, usize),
},
EmptyDimension {
what: &'static str,
},
NonFiniteDomain {
axis: &'static str,
},
IncompatibleScale {
detail: &'static str,
},
InvalidParameter {
detail: &'static str,
},
DimensionTooLarge {
what: &'static str,
requested: usize,
limit: usize,
},
AllocationFailed {
what: &'static str,
},
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::UnequalChannels { mark, lengths } => {
write!(
f,
"{mark}: channels differ in length ({} and {})",
lengths.0, lengths.1
)
}
Error::NonRectangular { mark, shape } => write!(
f,
"{mark}: {} values do not fill rows of {} columns",
shape.0, shape.1
),
Error::EmptyDimension { what } => write!(f, "{what} is empty"),
Error::NonFiniteDomain { axis } => write!(f, "the {axis} domain is not finite"),
Error::IncompatibleScale { detail } => write!(f, "incompatible scale: {detail}"),
Error::InvalidParameter { detail } => write!(f, "invalid parameter: {detail}"),
Error::DimensionTooLarge {
what,
requested,
limit,
} => write!(
f,
"{what} is too large (requested {requested}, limit {limit})"
),
Error::AllocationFailed { what } => {
write!(f, "could not reserve memory for {what}")
}
}
}
}
impl std::error::Error for Error {}
pub type Result<T> = std::result::Result<T, Error>;