summaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs34
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 @@
1use core::fmt;
2
3pub type MLE<T> = Result<T, MLError>;
4
5#[derive(Debug)]
6pub struct MLError {
7 etype: ErrorType,
8 message: String,
9}
10
11#[derive(Debug)]
12pub enum ErrorType {
13 ArgumentError
14}
15
16impl std::error::Error for MLError {
17 fn description(&self) -> &str {
18 &self.message
19 }
20}
21
22impl 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
30impl MLError {
31 pub fn new(etype: ErrorType, message: &str) -> Self {
32 Self { etype, message: String::from(message) }
33 }
34}