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
use std::error;
use std::fmt;
use std::io;

/// Raised when incorrect option is given during normal runtime
#[derive(Debug)]
pub struct OptionError {
    details: String,
}

impl OptionError {
    pub fn new(msg: String) -> OptionError {
        OptionError { details: msg }
    }
}

impl fmt::Display for OptionError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self.details)
    }
}

impl error::Error for OptionError {
    fn description(&self) -> &str {
        &self.details
    }
}

impl From<OptionError> for io::Error {
    fn from(err: OptionError) -> Self {
        io::Error::new(io::ErrorKind::Other, err)
    }
}