use self::Env::*;
use std::fmt;
#[non_exhaustive]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub enum Env {
#[default]
Dev,
Prod,
Custom(&'static str),
}
impl Env {
#[inline]
pub fn is_dev(&self) -> bool {
matches!(self, Dev)
}
#[inline]
pub fn is_prod(&self) -> bool {
matches!(self, Prod)
}
#[inline]
pub fn as_str(&self) -> &'static str {
match self {
Dev => "dev",
Prod => "prod",
Custom(name) => name,
}
}
}
impl fmt::Display for Env {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let env = self.as_str();
write!(f, "{env}")
}
}
impl From<&'static str> for Env {
#[inline]
fn from(env: &'static str) -> Self {
match env {
"dev" => Dev,
"prod" => Prod,
_ => Custom(env),
}
}
}