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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use std::borrow::{Cow};
use std::error::{Error};
use std::io::{self};
use walkdir::{self};
pub type ParseResult<T> = Result<T, ParseError>;
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
pub struct ParseError {
kind: ParseErrorKind,
detail: Cow<'static, str>
}
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum ParseErrorKind {
InvalidData,
MissingData,
CorruptData,
IoError
}
impl ParseError {
pub fn new<D>(kind: ParseErrorKind, detail: D) -> ParseError
where D: Into<Cow<'static, str>> {
ParseError{ kind: kind, detail: detail.into() }
}
pub fn kind(&self) -> ParseErrorKind {
self.kind
}
pub fn detail(&self) -> &str {
&self.detail
}
}
impl From<io::Error> for ParseError {
fn from(err: io::Error) -> ParseError {
ParseError::new(ParseErrorKind::IoError, err.to_string())
}
}
impl From<walkdir::Error> for ParseError {
fn from(err: walkdir::Error) -> ParseError {
ParseError::new(ParseErrorKind::IoError, err.description().to_owned())
}
}