dotenv_enum/env_errors.rs
1/// # Environment Enum Result
2/// Anything that isn't in the Ok status is an error.
3#[derive(PartialEq, Debug)]
4pub enum EnvEnumResult<T: Clone> {
5 Ok(T),
6 Absent(String),
7 IncorrectCast(String)
8}
9
10impl<T: Clone> EnvEnumResult<T> {
11 /// Will panic for everything that isn't Ok
12 /// ```
13 /// use dotenv_enum::env_errors::EnvEnumResult;
14 ///
15 /// assert_eq!(EnvEnumResult::Ok(4).panic_if_absent(), 4)
16 /// ```
17 pub fn panic_if_absent(&self) -> T {
18 match self {
19 EnvEnumResult::Ok(val) => val.clone(),
20 EnvEnumResult::Absent(message) => panic!("{}", message),
21 EnvEnumResult::IncorrectCast(message) => panic!("{}", message),
22 }
23 }
24}