2022-08-09 21:21:17 +00:00
|
|
|
use std::str::FromStr;
|
|
|
|
|
2023-02-05 21:30:51 +00:00
|
|
|
use super::ConfigError;
|
2022-08-09 21:21:17 +00:00
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub enum Environment {
|
|
|
|
Development,
|
|
|
|
Production,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Environment {
|
|
|
|
#[cfg(feature = "production")]
|
2023-04-24 15:35:32 +00:00
|
|
|
fn default() -> Self {
|
|
|
|
Self::Production
|
|
|
|
}
|
2022-08-09 21:21:17 +00:00
|
|
|
#[cfg(not(feature = "production"))]
|
2023-04-24 15:35:32 +00:00
|
|
|
fn default() -> Self {
|
|
|
|
Self::Development
|
|
|
|
}
|
2022-08-09 21:21:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for Environment {
|
2023-02-05 21:30:51 +00:00
|
|
|
type Err = ConfigError;
|
2022-08-09 21:21:17 +00:00
|
|
|
|
|
|
|
fn from_str(val: &str) -> Result<Self, Self::Err> {
|
|
|
|
let environment = match val {
|
|
|
|
"development" => Environment::Development,
|
|
|
|
"production" => Environment::Production,
|
2023-02-05 21:30:51 +00:00
|
|
|
_ => return Err(ConfigError("invalid environment type")),
|
2022-08-09 21:21:17 +00:00
|
|
|
};
|
|
|
|
Ok(environment)
|
|
|
|
}
|
|
|
|
}
|