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 { t: T, y: V,},
28 StepSize {
29 t: T, y: V,},
32 Stiffness {
33 t: T, y: V,},
36}
37
38impl<T, V> Display for Error<T, V>
39where
40 T: Real + Display,
41 V: State<T> + Display,
42{
43 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44 match self {
45 Self::BadInput { msg } => write!(f, "Bad Input: {}", msg),
46 Self::MaxSteps { t, y } => write!(f, "Maximum steps reached at (t, y) = ({}, {})", t, y),
47 Self::StepSize { t, y } => write!(f, "Step size too small at (t, y) = ({}, {})", t, y),
48 Self::Stiffness { t, y } => write!(f, "Stiffness detected at (t, y) = ({}, {})", t, y),
49 }
50 }
51}
52
53impl<T, V> Debug for Error<T, V>
54where
55 T: Real + Debug,
56 V: State<T> + Debug,
57{
58 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
59 match self {
60 Self::BadInput { msg } => write!(f, "Bad Input: {}", msg),
61 Self::MaxSteps { t, y } => write!(f, "Maximum steps reached at (t, y) = ({:?}, {:?})", t, y),
62 Self::StepSize { t, y } => write!(f, "Step size too small at (t, y) = ({:?}, {:?})", t, y),
63 Self::Stiffness { t, y } => write!(f, "Stiffness detected at (t, y) = ({:?}, {:?})", t, y),
64 }
65 }
66}
67
68impl<T, V> std::error::Error for Error<T, V>
69where
70 T: Real + Debug + Display,
71 V: State<T> + Debug + Display,
72{}