einstellung_derive 0.1.2

Proc-Macro crate for einstellung
Documentation
---
source: einstellung_derive/src/test.rs
expression: formatted
---
/// --- input ---
#[derive(Config)]
struct TelemetryConfig {
    enabled: bool,
    #[config(subconfig)]
    datadog: Option<DatadogConfig>,
}

/// --- output ---
#[derive(::core::default::Default, ::einstellung::serde::Deserialize)]
#[serde(crate = "::einstellung::serde")]
struct TelemetryConfigPartial {
    enabled: Option<bool>,
    datadog: Option<<DatadogConfig as ::einstellung::Config>::Partial>,
}
impl ::einstellung::PartialConfig for TelemetryConfigPartial {
    type Complete = TelemetryConfig;
    fn merge(
        self,
        next: Self,
    ) -> ::core::result::Result<Self, ::einstellung::ConfigError> {
        ::core::result::Result::Ok(Self {
            enabled: next.enabled.or(self.enabled),
            datadog: match (self.datadog, next.datadog) {
                (Some(a), Some(b)) => Some(::einstellung::PartialConfig::merge(a, b)?),
                (a, b) => a.or(b),
            },
        })
    }
    fn build(
        self,
    ) -> ::core::result::Result<Self::Complete, ::einstellung::ConfigError> {
        let enabled = self
            .enabled
            .ok_or(
                ::einstellung::ConfigError::MissingField(
                    ::einstellung::FieldPath::new("TelemetryConfig", "enabled"),
                ),
            )?;
        let datadog = self
            .datadog
            .map(|x| ::einstellung::build_with_context(x, "TelemetryConfig", "datadog"))
            .transpose()?;
        ::core::result::Result::Ok(TelemetryConfig {
            enabled,
            datadog,
        })
    }
}
impl ::einstellung::Config for TelemetryConfig {
    type Partial = TelemetryConfigPartial;
}

// ---------------------------------

/// --- input ---
#[derive(Config)]
struct DatadogConfig {
    api_key: String,
}

/// --- output ---
#[derive(::core::default::Default, ::einstellung::serde::Deserialize)]
#[serde(crate = "::einstellung::serde")]
struct DatadogConfigPartial {
    api_key: Option<String>,
}
impl ::einstellung::PartialConfig for DatadogConfigPartial {
    type Complete = DatadogConfig;
    fn merge(
        self,
        next: Self,
    ) -> ::core::result::Result<Self, ::einstellung::ConfigError> {
        ::core::result::Result::Ok(Self {
            api_key: next.api_key.or(self.api_key),
        })
    }
    fn build(
        self,
    ) -> ::core::result::Result<Self::Complete, ::einstellung::ConfigError> {
        let api_key = self
            .api_key
            .ok_or(
                ::einstellung::ConfigError::MissingField(
                    ::einstellung::FieldPath::new("DatadogConfig", "api_key"),
                ),
            )?;
        ::core::result::Result::Ok(DatadogConfig { api_key })
    }
}
impl ::einstellung::Config for DatadogConfig {
    type Partial = DatadogConfigPartial;
}