arachnid_cli/config/kinds/
services.rs1use 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 pub fn new() -> Self {
28 Self {
29 database: DatabaseConfig::new(),
30 tracing: TracingConfig::new(crate::config::LogLevel::Info),
31 }
32 }
33 pub const fn database(&self) -> &DatabaseConfig {
35 &self.database
36 }
37 pub const fn database_mut(&mut self) -> &mut DatabaseConfig {
39 &mut self.database
40 }
41 pub const fn tracing(&self) -> &TracingConfig {
43 &self.tracing
44 }
45 pub const fn tracing_mut(&mut self) -> &mut TracingConfig {
47 &mut self.tracing
48 }
49 pub fn set_database(&mut self, database: DatabaseConfig) {
51 self.database = database
52 }
53 pub const fn set_tracing(&mut self, tracing: TracingConfig) {
55 self.tracing = tracing
56 }
57 pub fn with_database(self, database: DatabaseConfig) -> Self {
59 Self { database, ..self }
60 }
61 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}