use std::fmt;
#[derive(Debug, Clone, PartialEq)]
pub enum Error {
InvalidInput {
field: &'static str,
reason: &'static str,
},
StepLimitExceeded {
limit: usize,
},
NumericalFailure(&'static str),
Model(String),
}
impl Error {
pub(crate) fn invalid(field: &'static str, reason: &'static str) -> Self {
Self::InvalidInput { field, reason }
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidInput { field, reason } => write!(f, "{field}: {reason}"),
Self::StepLimitExceeded { limit } => write!(f, "integration exceeded {limit} substeps"),
Self::NumericalFailure(reason) => write!(f, "integration failed: {reason}"),
Self::Model(message) => write!(f, "model failed: {message}"),
}
}
}
impl std::error::Error for Error {}
pub type Result<T> = std::result::Result<T, Error>;