einstellung_derive 0.1.6

Proc-Macro crate for einstellung
Documentation
---
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: ::core::option::Option<String>,
    port: ::core::option::Option<u16>,
    is_active: ::core::option::Option<bool>,
}
#[automatically_derived]
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> {
        ::core::result::Result::Ok(ServerConfig {
            host: self
                .host
                .ok_or(
                    ::einstellung::ConfigError::MissingField(
                        ::einstellung::FieldPath::new("ServerConfig", "host"),
                    ),
                )?,
            port: self
                .port
                .ok_or(
                    ::einstellung::ConfigError::MissingField(
                        ::einstellung::FieldPath::new("ServerConfig", "port"),
                    ),
                )?,
            is_active: self
                .is_active
                .ok_or(
                    ::einstellung::ConfigError::MissingField(
                        ::einstellung::FieldPath::new("ServerConfig", "is_active"),
                    ),
                )?,
        })
    }
}
#[automatically_derived]
impl ::einstellung::Config for ServerConfig {
    type Partial = ServerConfigPartial;
}