diff options
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..c82688c --- /dev/null +++ b/src/error.rs | |||
@@ -0,0 +1,34 @@ | |||
1 | use core::fmt; | ||
2 | |||
3 | pub type MLE<T> = Result<T, MLError>; | ||
4 | |||
5 | #[derive(Debug)] | ||
6 | pub struct MLError { | ||
7 | etype: ErrorType, | ||
8 | message: String, | ||
9 | } | ||
10 | |||
11 | #[derive(Debug)] | ||
12 | pub enum ErrorType { | ||
13 | ArgumentError | ||
14 | } | ||
15 | |||
16 | impl std::error::Error for MLError { | ||
17 | fn description(&self) -> &str { | ||
18 | &self.message | ||
19 | } | ||
20 | } | ||
21 | |||
22 | impl fmt::Display for MLError { | ||
23 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
24 | match self.etype { | ||
25 | ErrorType::ArgumentError => write!(f, "ARGS") | ||
26 | } | ||
27 | } | ||
28 | } | ||
29 | |||
30 | impl MLError { | ||
31 | pub fn new(etype: ErrorType, message: &str) -> Self { | ||
32 | Self { etype, message: String::from(message) } | ||
33 | } | ||
34 | } | ||