---
source: einstellung_derive/src/test.rs
expression: formatted
---
/// --- input ---
#[derive(Config)]
struct ServerConfig {
host: String,
port: u16,
is_active: bool,
}
/// --- output ---
#[derive(::core::default::Default, ::einstellung::serde::Deserialize)]
#[serde(crate = "::einstellung::serde")]
struct ServerConfigPartial {
host: Option<String>,
port: Option<u16>,
is_active: Option<bool>,
}
impl ::einstellung::PartialConfig for ServerConfigPartial {
type Complete = ServerConfig;
fn merge(
self,
next: Self,
) -> ::core::result::Result<Self, ::einstellung::ConfigError> {
::core::result::Result::Ok(Self {
host: next.host.or(self.host),
port: next.port.or(self.port),
is_active: next.is_active.or(self.is_active),
})
}
fn build(
self,
) -> ::core::result::Result<Self::Complete, ::einstellung::ConfigError> {
let host = self
.host
.ok_or(
::einstellung::ConfigError::MissingField(
::einstellung::FieldPath::new("ServerConfig", "host"),
),
)?;
let port = self
.port
.ok_or(
::einstellung::ConfigError::MissingField(
::einstellung::FieldPath::new("ServerConfig", "port"),
),
)?;
let is_active = self
.is_active
.ok_or(
::einstellung::ConfigError::MissingField(
::einstellung::FieldPath::new("ServerConfig", "is_active"),
),
)?;
::core::result::Result::Ok(ServerConfig {
host,
port,
is_active,
})
}
}
impl ::einstellung::Config for ServerConfig {
type Partial = ServerConfigPartial;
}