scsys_config/types/
mode.rs1#[derive(
8 Clone,
9 Copy,
10 Debug,
11 Default,
12 Eq,
13 Hash,
14 Ord,
15 PartialEq,
16 PartialOrd,
17 strum::AsRefStr,
18 strum::Display,
19 strum::EnumCount,
20 strum::EnumIs,
21 strum::EnumIter,
22 strum::EnumString,
23 strum::VariantArray,
24 strum::VariantNames,
25)]
26#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
27#[cfg_attr(
28 feature = "serde",
29 derive(serde::Deserialize, serde::Serialize),
30 serde(rename_all = "lowercase")
31)]
32#[strum(serialize_all = "lowercase")]
33pub enum Mode {
34 #[default]
35 #[cfg_attr(feature = "clap", clap(name = "debug"))]
36 #[cfg_attr(feature = "serde", serde(alias = "dev", alias = "development"))]
37 Debug,
38 #[cfg_attr(feature = "clap", clap(name = "release"))]
39 #[cfg_attr(feature = "serde", serde(alias = "prod", alias = "production"))]
40 Release,
41}
42
43impl Mode {
44 #[cfg(feature = "std")]
45 pub fn from_env() -> Self {
46 Self::from_env_with_varname("APP_MODE")
47 }
48 #[cfg(feature = "std")]
49 pub fn from_env_with_varname(var: &str) -> Self {
50 use core::str::FromStr;
51 std::env::var(var)
52 .map(|m| Self::from_str(&m).ok())
53 .ok()
54 .flatten()
55 .unwrap_or_default()
56 }
57
58 pub fn debug() -> Self {
59 Self::Debug
60 }
61
62 pub fn release() -> Self {
63 Self::Release
64 }
65}