differential_equations/
error.rs1use crate::traits::{Real, State};
4use std::fmt::{Debug, Display};
5
6#[derive(PartialEq, Clone)]
15pub enum Error<T, V>
16where
17 T: Real,
18 V: State<T>,
19{
20 BadInput {
22 msg: String, },
24 MaxSteps {
25 t: T, y: V, },
29 StepSize {
30 t: T, y: V, },
33 Stiffness {
34 t: T, y: V, },
37}
38
39impl<T, V> Display for Error<T, V>
40where
41 T: Real + Display,
42 V: State<T> + Display,
43{
44 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45 match self {
46 Self::BadInput { msg } => write!(f, "Bad Input: {}", msg),
47 Self::MaxSteps { t, y } => {
48 write!(f, "Maximum steps reached at (t, y) = ({}, {})", t, y)
49 }
50 Self::StepSize { t, y } => write!(f, "Step size too small at (t, y) = ({}, {})", t, y),
51 Self::Stiffness { t, y } => write!(f, "Stiffness detected at (t, y) = ({}, {})", t, y),
52 }
53 }
54}
55
56impl<T, V> Debug for Error<T, V>
57where
58 T: Real + Debug,
59 V: State<T> + Debug,
60{
61 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62 match self {
63 Self::BadInput { msg } => write!(f, "Bad Input: {}", msg),
64 Self::MaxSteps { t, y } => {
65 write!(f, "Maximum steps reached at (t, y) = ({:?}, {:?})", t, y)
66 }
67 Self::StepSize { t, y } => {
68 write!(f, "Step size too small at (t, y) = ({:?}, {:?})", t, y)
69 }
70 Self::Stiffness { t, y } => {
71 write!(f, "Stiffness detected at (t, y) = ({:?}, {:?})", t, y)
72 }
73 }
74 }
75}
76
77impl<T, V> std::error::Error for Error<T, V>
78where
79 T: Real + Debug + Display,
80 V: State<T> + Debug + Display,
81{
82}