1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use snafu::{Backtrace, GenerateBacktrace, Snafu};

#[derive(Debug, Snafu)]
#[snafu(visibility(pub(crate)))]
pub enum Error {
    #[snafu(display("mexprp error: {}", description))]
    MexprpError {
        description: String,
        backtrace: Backtrace,
    },

    #[snafu(display(
        "Equation with multiple result not supported for integral bounds, equation: {}",
        equation
    ))]
    EquationWithMultipleResult {
        equation: String,
        backtrace: Backtrace,
    },

    #[snafu(display("RangeGenerator step{} out of b bound{}", step, b))]
    RangeGeneratorOutOfBounds {
        step: f64,
        b: f64,
        backtrace: Backtrace,
    },

    #[snafu(display("Begin bound{} greater than end bound{}", a, b))]
    BeginBoundGreaterThanEndBound {
        a: f64,
        b: f64,
        backtrace: Backtrace,
    },
}

pub type Result<T, E = Error> = std::result::Result<T, E>;

impl From<mexprp::ParseError> for Error {
    fn from(error: mexprp::ParseError) -> Self {
        Error::MexprpError {
            description: error.to_string(),
            backtrace: Backtrace::generate(),
        }
    }
}

impl From<mexprp::MathError> for Error {
    fn from(error: mexprp::MathError) -> Self {
        Error::MexprpError {
            description: error.to_string(),
            backtrace: Backtrace::generate(),
        }
    }
}

impl From<mexprp::EvalError> for Error {
    fn from(error: mexprp::EvalError) -> Self {
        Error::MexprpError {
            description: error.to_string(),
            backtrace: Backtrace::generate(),
        }
    }
}