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
#[cfg(test)]
#[path = "./errors_test.rs"]
mod errors_test;
use std::error::Error;
use std::fmt;
use std::fmt::Display;
#[derive(Debug, Copy, Clone)]
pub enum ErrorKind {
FileNotFound(&'static str),
FileOpen(&'static str),
}
#[derive(Debug, Copy, Clone)]
pub struct EnvmntError {
pub kind: ErrorKind,
}
impl Error for EnvmntError {
fn description(&self) -> &str {
match self.kind {
ErrorKind::FileNotFound(description) => description,
ErrorKind::FileOpen(description) => description,
}
}
}
impl Display for EnvmntError {
fn fmt(&self, format: &mut fmt::Formatter) -> Result<(), fmt::Error> {
match self.kind {
ErrorKind::FileNotFound(ref file) => file.fmt(format),
ErrorKind::FileOpen(ref file) => file.fmt(format),
}
}
}
impl EnvmntError {
pub fn is_file_not_found(&self) -> bool {
match self.kind {
ErrorKind::FileNotFound(_) => true,
_ => false,
}
}
pub fn is_file_open(&self) -> bool {
match self.kind {
ErrorKind::FileOpen(_) => true,
_ => false,
}
}
}