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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use std::error::Error;
use std::fmt;
use std::io;
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum ParseError {
OverflowError,
ParseIntError,
UnsupportedBase
}
unsafe impl Send for ParseError {}
unsafe impl Sync for ParseError {}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ParseError::OverflowError => write!(f, "Overflow"),
ParseError::ParseIntError => write!(f, "Could not parse integer"),
ParseError::UnsupportedBase => write!(f, "Unsupported base")
}
}
}
impl Error for ParseError {}
#[derive(Debug)]
pub enum DivisionError {
DivisionByZero,
FmtError(fmt::Error),
IoError(io::Error),
ExternalError(Box<Error + Send + Sync>)
}
unsafe impl Sync for DivisionError {}
unsafe impl Send for DivisionError {}
impl fmt::Display for DivisionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
DivisionError::DivisionByZero => write!(f, "Division by zero"),
DivisionError::FmtError(e) => write!(f, "Fmt error: {}", e),
DivisionError::IoError(e) => write!(f, "IO error: {}", e),
DivisionError::ExternalError(e) => write!(f, "External error: {}", e),
}
}
}
impl Error for DivisionError {}
impl From<io::Error> for DivisionError {
fn from(error: io::Error) -> DivisionError {
DivisionError::IoError(error)
}
}
impl From<fmt::Error> for DivisionError {
fn from(error: fmt::Error) -> DivisionError {
DivisionError::FmtError(error)
}
}