summaryrefslogtreecommitdiff
path: root/src/error.rs
blob: c82688c9d9ac35f6fad4f058abb13cc8076f3fc3 (plain) (blame)
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
use core::fmt;

pub type MLE<T> = Result<T, MLError>;

#[derive(Debug)]
pub struct MLError {
    etype: ErrorType,
    message: String,
}

#[derive(Debug)]
pub enum ErrorType {
    ArgumentError
}

impl std::error::Error for MLError {
    fn description(&self) -> &str {
        &self.message
    }
}

impl fmt::Display for MLError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self.etype {
            ErrorType::ArgumentError => write!(f, "ARGS")
        }
    }
}

impl MLError {
    pub fn new(etype: ErrorType, message: &str) -> Self {
        Self { etype, message: String::from(message) }
    }
}