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
use std::io;
use std::num;
use std::result;

#[derive(Debug)]
pub enum ParseError {
    Integer(num::ParseIntError),
    Float(num::ParseFloatError)
}

#[derive(Debug)]
pub enum Error {
    IO(io::Error),
    IllegalState(String),
    Parse(ParseError)
}

impl From<io::Error> for Error {
    fn from(err: io::Error) -> Self {
        Error::IO(err)
    }
}

impl From<num::ParseIntError> for Error {
    fn from(err: num::ParseIntError) -> Self {
        Error::Parse(ParseError::Integer(err))
    }
}

impl From<num::ParseFloatError> for Error {
    fn from(err: num::ParseFloatError) -> Self {
        Error::Parse(ParseError::Float(err))
    }
}

pub type Result<T> = result::Result<T, Error>;