diff --git a/crates/config/src/sections/branding.rs b/crates/config/src/sections/branding.rs index 7b6c060b..5bdc79a5 100644 --- a/crates/config/src/sections/branding.rs +++ b/crates/config/src/sections/branding.rs @@ -46,9 +46,7 @@ pub struct BrandingConfig { #[async_trait] impl ConfigurationSection for BrandingConfig { - fn path() -> &'static str { - "branding" - } + const PATH: Option<&'static str> = Some("branding"); async fn generate(_rng: R) -> anyhow::Result where diff --git a/crates/config/src/sections/clients.rs b/crates/config/src/sections/clients.rs index 0d69d871..cf51acda 100644 --- a/crates/config/src/sections/clients.rs +++ b/crates/config/src/sections/clients.rs @@ -181,9 +181,7 @@ impl IntoIterator for ClientsConfig { #[async_trait] impl ConfigurationSection for ClientsConfig { - fn path() -> &'static str { - "clients" - } + const PATH: Option<&'static str> = Some("clients"); async fn generate(_rng: R) -> anyhow::Result where diff --git a/crates/config/src/sections/database.rs b/crates/config/src/sections/database.rs index a7bbf1ab..c7521161 100644 --- a/crates/config/src/sections/database.rs +++ b/crates/config/src/sections/database.rs @@ -146,9 +146,7 @@ pub struct DatabaseConfig { #[async_trait] impl ConfigurationSection for DatabaseConfig { - fn path() -> &'static str { - "database" - } + const PATH: Option<&'static str> = Some("database"); async fn generate(_rng: R) -> anyhow::Result where diff --git a/crates/config/src/sections/email.rs b/crates/config/src/sections/email.rs index 3bf85106..77beb838 100644 --- a/crates/config/src/sections/email.rs +++ b/crates/config/src/sections/email.rs @@ -128,9 +128,7 @@ impl Default for EmailConfig { #[async_trait] impl ConfigurationSection for EmailConfig { - fn path() -> &'static str { - "email" - } + const PATH: Option<&'static str> = Some("email"); async fn generate(_rng: R) -> anyhow::Result where diff --git a/crates/config/src/sections/experimental.rs b/crates/config/src/sections/experimental.rs index 594abac2..c98a435c 100644 --- a/crates/config/src/sections/experimental.rs +++ b/crates/config/src/sections/experimental.rs @@ -56,9 +56,7 @@ impl Default for ExperimentalConfig { #[async_trait] impl ConfigurationSection for ExperimentalConfig { - fn path() -> &'static str { - "experimental" - } + const PATH: Option<&'static str> = Some("experimental"); async fn generate(_rng: R) -> anyhow::Result where diff --git a/crates/config/src/sections/http.rs b/crates/config/src/sections/http.rs index 1771155a..93036a5c 100644 --- a/crates/config/src/sections/http.rs +++ b/crates/config/src/sections/http.rs @@ -394,9 +394,7 @@ impl Default for HttpConfig { #[async_trait] impl ConfigurationSection for HttpConfig { - fn path() -> &'static str { - "http" - } + const PATH: Option<&'static str> = Some("http"); async fn generate(_rng: R) -> anyhow::Result where diff --git a/crates/config/src/sections/matrix.rs b/crates/config/src/sections/matrix.rs index 9d072978..465a70cf 100644 --- a/crates/config/src/sections/matrix.rs +++ b/crates/config/src/sections/matrix.rs @@ -50,9 +50,7 @@ pub struct MatrixConfig { #[async_trait] impl ConfigurationSection for MatrixConfig { - fn path() -> &'static str { - "matrix" - } + const PATH: Option<&'static str> = Some("matrix"); async fn generate(mut rng: R) -> anyhow::Result where diff --git a/crates/config/src/sections/mod.rs b/crates/config/src/sections/mod.rs index 81706cde..6032664e 100644 --- a/crates/config/src/sections/mod.rs +++ b/crates/config/src/sections/mod.rs @@ -116,10 +116,6 @@ pub struct RootConfig { #[async_trait] impl ConfigurationSection for RootConfig { - fn path() -> &'static str { - "" - } - async fn generate(mut rng: R) -> anyhow::Result where R: Rng + Send, @@ -195,10 +191,6 @@ pub struct AppConfig { #[async_trait] impl ConfigurationSection for AppConfig { - fn path() -> &'static str { - "" - } - async fn generate(mut rng: R) -> anyhow::Result where R: Rng + Send, @@ -251,10 +243,6 @@ pub struct SyncConfig { #[async_trait] impl ConfigurationSection for SyncConfig { - fn path() -> &'static str { - "" - } - async fn generate(mut rng: R) -> anyhow::Result where R: Rng + Send, diff --git a/crates/config/src/sections/passwords.rs b/crates/config/src/sections/passwords.rs index 9a6cf59e..9835a8da 100644 --- a/crates/config/src/sections/passwords.rs +++ b/crates/config/src/sections/passwords.rs @@ -57,9 +57,7 @@ impl Default for PasswordsConfig { #[async_trait] impl ConfigurationSection for PasswordsConfig { - fn path() -> &'static str { - "passwords" - } + const PATH: Option<&'static str> = Some("passwords"); async fn generate(_rng: R) -> anyhow::Result where diff --git a/crates/config/src/sections/policy.rs b/crates/config/src/sections/policy.rs index b3e14954..b10c12b3 100644 --- a/crates/config/src/sections/policy.rs +++ b/crates/config/src/sections/policy.rs @@ -106,9 +106,7 @@ impl Default for PolicyConfig { #[async_trait] impl ConfigurationSection for PolicyConfig { - fn path() -> &'static str { - "policy" - } + const PATH: Option<&'static str> = Some("policy"); async fn generate(_rng: R) -> anyhow::Result where diff --git a/crates/config/src/sections/secrets.rs b/crates/config/src/sections/secrets.rs index a15babc8..1e3b8e1c 100644 --- a/crates/config/src/sections/secrets.rs +++ b/crates/config/src/sections/secrets.rs @@ -139,9 +139,7 @@ impl SecretsConfig { #[async_trait] impl ConfigurationSection for SecretsConfig { - fn path() -> &'static str { - "secrets" - } + const PATH: Option<&'static str> = Some("secrets"); #[tracing::instrument(skip_all)] async fn generate(mut rng: R) -> anyhow::Result diff --git a/crates/config/src/sections/telemetry.rs b/crates/config/src/sections/telemetry.rs index 6a7dcef4..1f5a77bc 100644 --- a/crates/config/src/sections/telemetry.rs +++ b/crates/config/src/sections/telemetry.rs @@ -145,9 +145,7 @@ pub struct TelemetryConfig { #[async_trait] impl ConfigurationSection for TelemetryConfig { - fn path() -> &'static str { - "telemetry" - } + const PATH: Option<&'static str> = Some("telemetry"); async fn generate(_rng: R) -> anyhow::Result where diff --git a/crates/config/src/sections/templates.rs b/crates/config/src/sections/templates.rs index 40e99b35..b146dd7b 100644 --- a/crates/config/src/sections/templates.rs +++ b/crates/config/src/sections/templates.rs @@ -96,9 +96,7 @@ impl Default for TemplatesConfig { #[async_trait] impl ConfigurationSection for TemplatesConfig { - fn path() -> &'static str { - "templates" - } + const PATH: Option<&'static str> = Some("templates"); async fn generate(_rng: R) -> anyhow::Result where diff --git a/crates/config/src/sections/upstream_oauth2.rs b/crates/config/src/sections/upstream_oauth2.rs index c3b7b0ca..b73d7707 100644 --- a/crates/config/src/sections/upstream_oauth2.rs +++ b/crates/config/src/sections/upstream_oauth2.rs @@ -34,9 +34,7 @@ pub struct UpstreamOAuth2Config { #[async_trait] impl ConfigurationSection for UpstreamOAuth2Config { - fn path() -> &'static str { - "upstream_oauth2" - } + const PATH: Option<&'static str> = Some("upstream_oauth2"); async fn generate(_rng: R) -> anyhow::Result where diff --git a/crates/config/src/util.rs b/crates/config/src/util.rs index f3a2fb7e..fefe365c 100644 --- a/crates/config/src/util.rs +++ b/crates/config/src/util.rs @@ -22,7 +22,7 @@ use serde::{de::DeserializeOwned, Serialize}; /// of the config and generate the sample config. pub trait ConfigurationSection: Sized + DeserializeOwned + Serialize { /// Specify where this section should live relative to the root. - fn path() -> &'static str; + const PATH: Option<&'static str> = None; /// Generate a sample configuration for this section. async fn generate(rng: R) -> anyhow::Result @@ -35,7 +35,11 @@ pub trait ConfigurationSection: Sized + DeserializeOwned + Serialize { /// /// Returns an error if the configuration could not be loaded fn extract(figment: &Figment) -> Result { - figment.extract_inner(Self::path()) + if let Some(path) = Self::PATH { + figment.extract_inner(path) + } else { + figment.extract() + } } /// Generate config used in unit tests