1use crate::traits::Real;
4use nalgebra::SMatrix;
5use std::fmt::{Debug, Display};
6
7#[derive(PartialEq, Clone)]
16pub enum Error<T, const R: usize, const C: usize>
17where
18 T: Real,
19{
20 BadInput {
22 msg: String, },
24 MaxSteps { t: T, y: SMatrix<T, R, C>,},
28 StepSize {
29 t: T, y: SMatrix<T, R, C>,},
32 Stiffness {
33 t: T, y: SMatrix<T, R, C>,},
36}
37
38impl<T, const R: usize, const C: usize> Display for Error<T, R, C>
39where
40 T: Real + Display,
41{
42 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43 match self {
44 Self::BadInput { msg } => write!(f, "Bad Input: {}", msg),
45 Self::MaxSteps { t, y } => write!(f, "Maximum steps reached at (t, y) = ({}, {})", t, y),
46 Self::StepSize { t, y } => write!(f, "Step size too small at (t, y) = ({}, {})", t, y),
47 Self::Stiffness { t, y } => write!(f, "Stiffness detected at (t, y) = ({}, {})", t, y),
48 }
49 }
50}
51
52impl<T, const R: usize, const C: usize> Debug for Error<T, R, C>
53where
54 T: Real + Debug,
55{
56 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57 match self {
58 Self::BadInput { msg } => write!(f, "Bad Input: {}", msg),
59 Self::MaxSteps { t, y } => write!(f, "Maximum steps reached at (t, y) = ({}, {})", t, y),
60 Self::StepSize { t, y } => write!(f, "Step size too small at (t, y) = ({}, {})", t, y),
61 Self::Stiffness { t, y } => write!(f, "Stiffness detected at (t, y) = ({}, {})", t, y),
62 }
63 }
64}
65
66impl<T, const R: usize, const C: usize> std::error::Error for Error<T, R, C>
67where
68 T: Real + Debug,
69{}