use super::{DatabaseConfig, TracingConfig};
#[derive(
Clone,
Debug,
Default,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
serde::Deserialize,
serde::Serialize,
)]
#[serde(default)]
pub struct ServicesConfig {
pub database: DatabaseConfig,
pub tracing: TracingConfig,
}
impl ServicesConfig {
pub fn new() -> Self {
Self {
database: DatabaseConfig::new(),
tracing: TracingConfig::new(crate::config::LogLevel::Info),
}
}
pub const fn database(&self) -> &DatabaseConfig {
&self.database
}
pub const fn database_mut(&mut self) -> &mut DatabaseConfig {
&mut self.database
}
pub const fn tracing(&self) -> &TracingConfig {
&self.tracing
}
pub const fn tracing_mut(&mut self) -> &mut TracingConfig {
&mut self.tracing
}
pub fn set_database(&mut self, database: DatabaseConfig) {
self.database = database
}
pub const fn set_tracing(&mut self, tracing: TracingConfig) {
self.tracing = tracing
}
pub fn with_database(self, database: DatabaseConfig) -> Self {
Self { database, ..self }
}
pub fn with_tracing(self, tracing: TracingConfig) -> Self {
Self { tracing, ..self }
}
}
impl core::fmt::Display for ServicesConfig {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write! { f, "{{ database: {}, tracing: {} }}", self.database, self.tracing }
}
}