Skip to main content

backbone_core/config/
app_config.rs

1//! Application configuration
2//!
3//! Defines application metadata and environment settings.
4
5use serde::{Deserialize, Serialize};
6
7/// Application metadata configuration
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct AppConfig {
10    /// Application name
11    pub name: String,
12    /// Application version
13    pub version: String,
14    /// Application description
15    #[serde(default)]
16    pub description: Option<String>,
17    /// Application author
18    #[serde(default)]
19    pub author: Option<String>,
20    /// Enable debug mode
21    #[serde(default)]
22    pub debug: bool,
23    /// Current environment
24    #[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/// Application environment
42#[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}