arachnid_cli/config/kinds/
services.rs

1/*
2    Appellation: services <module>
3    Contrib: @FL03
4*/
5use super::{DatabaseConfig, TracingConfig};
6
7#[derive(
8    Clone,
9    Debug,
10    Default,
11    Eq,
12    Hash,
13    Ord,
14    PartialEq,
15    PartialOrd,
16    serde::Deserialize,
17    serde::Serialize,
18)]
19#[serde(default)]
20pub struct ServicesConfig {
21    pub database: DatabaseConfig,
22    pub tracing: TracingConfig,
23}
24
25impl ServicesConfig {
26    /// initialize a new instance of the services configuration
27    pub fn new() -> Self {
28        Self {
29            database: DatabaseConfig::new(),
30            tracing: TracingConfig::new(crate::config::LogLevel::Info),
31        }
32    }
33    /// returns a reference to the database configuration
34    pub const fn database(&self) -> &DatabaseConfig {
35        &self.database
36    }
37    /// returns a mutable reference to the database configuration
38    pub const fn database_mut(&mut self) -> &mut DatabaseConfig {
39        &mut self.database
40    }
41    /// returns a reference to the tracing configuration
42    pub const fn tracing(&self) -> &TracingConfig {
43        &self.tracing
44    }
45    /// returns a mutable reference to the tracing configuration
46    pub const fn tracing_mut(&mut self) -> &mut TracingConfig {
47        &mut self.tracing
48    }
49    /// update the database configuration
50    pub fn set_database(&mut self, database: DatabaseConfig) {
51        self.database = database
52    }
53    /// update the tracing configuration
54    pub const fn set_tracing(&mut self, tracing: TracingConfig) {
55        self.tracing = tracing
56    }
57    /// consumes the current instance to set the database configuration
58    pub fn with_database(self, database: DatabaseConfig) -> Self {
59        Self { database, ..self }
60    }
61    /// consumes the current instance to set the tracing configuration
62    pub fn with_tracing(self, tracing: TracingConfig) -> Self {
63        Self { tracing, ..self }
64    }
65}
66
67impl core::fmt::Display for ServicesConfig {
68    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
69        write! { f, "{{ database: {}, tracing: {} }}", self.database, self.tracing }
70    }
71}