backbone_core/config/
app_config.rs1use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct AppConfig {
10 pub name: String,
12 pub version: String,
14 #[serde(default)]
16 pub description: Option<String>,
17 #[serde(default)]
19 pub author: Option<String>,
20 #[serde(default)]
22 pub debug: bool,
23 #[serde(default)]
25 pub environment: Environment,
26}
27
28impl Default for AppConfig {
29 fn default() -> Self {
30 Self {
31 name: "Backbone Application".to_string(),
32 version: "1.0.0".to_string(),
33 description: None,
34 author: None,
35 debug: true,
36 environment: Environment::Development,
37 }
38 }
39}
40
41#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
43#[serde(rename_all = "lowercase")]
44pub enum Environment {
45 #[default]
46 Development,
47 Staging,
48 Production,
49}
50
51impl std::fmt::Display for Environment {
52 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53 match self {
54 Environment::Development => write!(f, "development"),
55 Environment::Staging => write!(f, "staging"),
56 Environment::Production => write!(f, "production"),
57 }
58 }
59}
60
61impl std::str::FromStr for Environment {
62 type Err = String;
63
64 fn from_str(s: &str) -> Result<Self, Self::Err> {
65 match s.to_lowercase().as_str() {
66 "development" | "dev" => Ok(Environment::Development),
67 "staging" | "stage" => Ok(Environment::Staging),
68 "production" | "prod" => Ok(Environment::Production),
69 _ => Err(format!("Unknown environment: {}", s)),
70 }
71 }
72}