1use std::fmt::{Display, Formatter};
2
3#[derive(Debug, Clone, PartialEq)]
5pub struct EquationError {
6 pub message: String,
8 pub type_: EquationErrorType,
10}
11
12impl EquationError {
13 pub fn new(message: String, type_: EquationErrorType) -> EquationError {
15 EquationError { message, type_ }
16 }
17}
18
19#[derive(Debug, Clone, PartialEq)]
21pub enum EquationErrorType {
22 MissingItems,
24 UnexpectedToken,
26 UnsetVariable,
28}
29
30impl Display for EquationError {
31 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
32 write!(f, "{:?} {}", self.type_, self.message)
33 }
34}
35
36impl std::error::Error for EquationError {
37 fn description(&self) -> &str {
38 &self.message
39 }
40}