---
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: ::core::option::Option<bool>,
datadog: ::core::option::Option<<DatadogConfig as ::einstellung::Config>::Partial>,
}
#[automatically_derived]
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> {
::core::result::Result::Ok(TelemetryConfig {
enabled: self
.enabled
.ok_or(
::einstellung::ConfigError::MissingField(
::einstellung::FieldPath::new("TelemetryConfig", "enabled"),
),
)?,
datadog: self
.datadog
.map(|x| ::einstellung::build_with_context(
x,
"TelemetryConfig",
"datadog",
))
.transpose()?,
})
}
}
#[automatically_derived]
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: ::core::option::Option<String>,
}
#[automatically_derived]
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> {
::core::result::Result::Ok(DatadogConfig {
api_key: self
.api_key
.ok_or(
::einstellung::ConfigError::MissingField(
::einstellung::FieldPath::new("DatadogConfig", "api_key"),
),
)?,
})
}
}
#[automatically_derived]
impl ::einstellung::Config for DatadogConfig {
type Partial = DatadogConfigPartial;
}