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

use std::fmt;
use std::error::Error;

#[derive(Debug, PartialEq)]
pub enum AsteroidResult {
    Ok,
    Err(AsteroidError),
}

#[derive(Debug, PartialEq)]
pub struct AsteroidError {
    kind: AsteroidErrorKind,
    msg: String,
}

#[derive(Debug, PartialEq)]
pub enum AsteroidErrorKind {
    InvalidSettingsFormat,
}

impl AsteroidError {
    pub fn new(kind: AsteroidErrorKind, msg: &str) -> Self {
        AsteroidError {
            kind: kind,
            msg: msg.to_owned(),
        }
    }
}

impl fmt::Display for AsteroidError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "An error has ocurred: {:?} {}", self.kind, self.msg)
    }
}

impl Error for AsteroidError {
    fn description(&self) -> &str {
        &self.msg
    }
}