1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq)]
5pub enum Error {
6 InvalidInput {
8 field: &'static str,
10 reason: &'static str,
12 },
13 StepLimitExceeded {
15 limit: usize,
17 },
18 NumericalFailure(&'static str),
20 Model(String),
22}
23
24impl Error {
25 pub(crate) fn invalid(field: &'static str, reason: &'static str) -> Self {
26 Self::InvalidInput { field, reason }
27 }
28}
29
30impl fmt::Display for Error {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 match self {
33 Self::InvalidInput { field, reason } => write!(f, "{field}: {reason}"),
34 Self::StepLimitExceeded { limit } => write!(f, "integration exceeded {limit} substeps"),
35 Self::NumericalFailure(reason) => write!(f, "integration failed: {reason}"),
36 Self::Model(message) => write!(f, "model failed: {message}"),
37 }
38 }
39}
40
41impl std::error::Error for Error {}
42
43pub type Result<T> = std::result::Result<T, Error>;