1use std::io;
2use std::fmt;
3use std::error;
4use std::num::ParseIntError;
5
6#[derive(Debug)]
7pub enum CsaStreamReadError {
8 IOError(io::Error),
9}
10impl fmt::Display for CsaStreamReadError {
11 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
12 match *self {
13 CsaStreamReadError::IOError(_) => write!(f, "Error occurred in file I/O."),
14 }
15 }
16}
17impl error::Error for CsaStreamReadError {
18 fn description(&self) -> &str {
19 match *self {
20 CsaStreamReadError::IOError(_) => "Error occurred in file I/O.",
21 }
22 }
23
24 fn source(&self) -> Option<&(dyn error::Error + 'static)> {
25 match *self {
26 CsaStreamReadError::IOError(ref e) => Some(e),
27 }
28 }
29}
30impl From<io::Error> for CsaStreamReadError {
31 fn from(err: io::Error) -> CsaStreamReadError {
32 CsaStreamReadError::IOError(err)
33 }
34}
35#[derive(Debug)]
36pub enum CsaParserError {
37 StreamReadError(CsaStreamReadError),
38 FormatError(String),
39 ParseIntError(ParseIntError),
40 InvalidStateError(String),
41}
42impl fmt::Display for CsaParserError {
43 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
44 match *self {
45 CsaParserError::StreamReadError(_) => write!(f, "There was an error loading the stream."),
46 CsaParserError::FormatError(ref s) => write!(f, "Invalid format. ({})",s),
47 CsaParserError::ParseIntError(ref e) => write!(f, "parse int error. ({})",e),
48 CsaParserError::InvalidStateError (ref s) => write!(f, "Invalid read state. ({})",s),
49 }
50 }
51}
52impl error::Error for CsaParserError {
53 fn description(&self) -> &str {
54 match *self {
55 CsaParserError::StreamReadError(_) => "There was an error loading the stream.",
56 CsaParserError::FormatError(_) => "Invalid format.",
57 CsaParserError::ParseIntError(_) => "parse int error.",
58 CsaParserError::InvalidStateError(_) => "Invalid read state.",
59 }
60 }
61
62 fn source(&self) -> Option<&(dyn error::Error + 'static)> {
63 match *self {
64 CsaParserError::StreamReadError(ref e) => Some(e),
65 CsaParserError::FormatError(_) => None,
66 CsaParserError::ParseIntError(ref e) => Some(e),
67 CsaParserError::InvalidStateError(_) => None,
68 }
69 }
70}
71impl From<CsaStreamReadError> for CsaParserError {
72 fn from(err: CsaStreamReadError) -> CsaParserError {
73 CsaParserError::StreamReadError(err)
74 }
75}
76impl From<ParseIntError> for CsaParserError {
77 fn from(err: ParseIntError) -> CsaParserError {
78 CsaParserError::ParseIntError(err)
79 }
80}
81impl From<CsaStateError> for CsaParserError {
82 fn from(err: CsaStateError) -> CsaParserError {
83 match err {
84 CsaStateError::InvalidStateError(s) => CsaParserError::InvalidStateError(s)
85 }
86 }
87}
88#[derive(Debug)]
89pub enum CsaStateError {
90 InvalidStateError(String),
91}
92impl fmt::Display for CsaStateError {
93 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
94 match *self {
95 CsaStateError::InvalidStateError (ref s) => write!(f,"Invalid read state. ({})",s),
96 }
97 }
98}
99impl error::Error for CsaStateError {
100 fn description(&self) -> &str {
101 match *self {
102 CsaStateError::InvalidStateError(_) => "Invalid read state.",
103 }
104 }
105
106 fn source(&self) -> Option<&(dyn error::Error + 'static)> {
107 match *self {
108 CsaStateError::InvalidStateError(_) => None,
109 }
110 }
111}