1use std::env;
2use std::error;
3use std::fmt;
4use std::io;
5
6#[derive(Debug)]
7#[non_exhaustive]
8pub enum Error {
9 Io(io::Error),
10 Env(env::VarError),
11}
12
13impl Error {
14 pub fn is_not_found(&self) -> bool {
15 if let Error::Io(err) = self {
16 return err.kind() == io::ErrorKind::NotFound;
17 }
18
19 false
20 }
21
22 pub(crate) fn not_found() -> Self {
23 io::Error::new(io::ErrorKind::NotFound, "path not found").into()
24 }
25}
26
27impl fmt::Display for Error {
28 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
29 match self {
30 Error::Io(err) => err.fmt(fmt),
31 Error::Env(err) => err.fmt(fmt),
32 }
33 }
34}
35
36impl error::Error for Error {
37 fn source(&self) -> Option<&(dyn error::Error + 'static)> {
38 match self {
39 Error::Io(err) => Some(err),
40 Error::Env(err) => Some(err),
41 }
42 }
43}
44
45impl From<io::Error> for Error {
46 fn from(err: io::Error) -> Self {
47 Error::Io(err)
48 }
49}
50
51impl From<env::VarError> for Error {
52 fn from(err: env::VarError) -> Self {
53 Error::Env(err)
54 }
55}