Skip to main content

rustils/impls/
error_impl.rs

1use std::fmt;
2use std::fmt::{ Display, Formatter };
3use std::error::Error;
4use error::*;
5
6impl Error for ParseError {
7    fn description(&self) -> &'static str {
8        match self{
9            &ParseError::InvalidNumber(_) => "Invalid Number",
10            &ParseError::InvalidString(_) => "Invalid String"
11        }
12    }
13
14    fn cause(&self) -> Option<&dyn Error> { None }
15}
16
17impl Display for ParseError {
18    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
19        match self{
20            &ParseError::InvalidNumber(ref i) => write!(f, "Invalid Number: {}", i),
21            &ParseError::InvalidString(ref i) => write!(f, "Invalid String: {}", i)
22        }
23    }
24}
25
26impl Error for ArithmeticError {
27    fn description(&self) -> &'static str {
28        match self{
29            &ArithmeticError::DivideByZero => "DivideByZero"
30        }
31    }
32
33    fn cause(&self) -> Option<&dyn Error> { None }
34}
35
36impl Display for ArithmeticError {
37    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
38        match self{
39            &ArithmeticError::DivideByZero => write!(f, "DivideByZero")
40        }
41    }
42}