fedimovies/fedimovies-config/src/environment.rs

34 lines
733 B
Rust
Raw Normal View History

2022-08-09 21:21:17 +00:00
use std::str::FromStr;
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 {
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,
_ => return Err(ConfigError("invalid environment type")),
2022-08-09 21:21:17 +00:00
};
Ok(environment)
}
}