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
#[cfg(test)]
#[path = "./errors_test.rs"]
mod errors_test;
use fsio::error::FsIOError;
use std::error::Error;
use std::fmt;
use std::fmt::Display;
#[derive(Debug)]
pub enum EnvmntError {
ReadFile(&'static str, FsIOError),
Missing(String),
InvalidType(String),
}
impl Display for EnvmntError {
fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
match self {
Self::ReadFile(ref message, ref cause) => {
writeln!(formatter, "{}", message)?;
cause.fmt(formatter)
}
Self::Missing(ref msg) => writeln!(formatter, "{}", msg),
Self::InvalidType(ref msg) => writeln!(formatter, "{}", msg),
}
}
}
impl Error for EnvmntError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::ReadFile(_, error) => Some(error),
Self::Missing(_) => None,
Self::InvalidType(_) => None,
}
}
}