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
use std::error;
use std::fmt;

/// The error type for operations interacting with environment variables
#[derive(Debug, PartialEq)]
pub enum EnvError {
    /// The specified environment variable was not present in the current process's environment.
    MissingVariable(String),

    /// Failed to parse the specified environment variable.
    FailedToParse(String),
}

impl fmt::Display for EnvError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match &self {
            EnvError::MissingVariable(env_name) => {
                write!(f, r#"Environment variable "{}" is missing"#, env_name)
            }
            EnvError::FailedToParse(env_name) => {
                write!(f, r#"Failed to parse environment variable "{}""#, env_name)
            }
        }
    }
}

impl error::Error for EnvError {}