1use core::fmt;
8
9#[derive(Clone, Debug, PartialEq)]
11pub enum SpecialError {
12 Domain(String),
14 Convergence {
16 function: &'static str,
17 iterations: usize,
18 },
19}
20
21impl fmt::Display for SpecialError {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 match self {
24 Self::Domain(msg) => write!(f, "domain error: {msg}"),
25 Self::Convergence {
26 function,
27 iterations,
28 } => {
29 write!(
30 f,
31 "{function} did not converge after {iterations} iterations"
32 )
33 }
34 }
35 }
36}
37
38impl From<SpecialError> for numra_core::NumraError {
39 fn from(e: SpecialError) -> Self {
40 numra_core::NumraError::Special(e.to_string())
41 }
42}