einstellung_derive 0.1.6

Proc-Macro crate for einstellung
Documentation
---
source: einstellung_derive/src/test.rs
expression: formatted
---
/// --- input ---
#[derive(Config)]
struct NetworkConfig {
    #[config(default = ||"localhost".to_string())]
    host: String,
    #[config(default = 8080)]
    port: u16,
    #[config(default = ||std::time::Duration::from_secs(30))]
    timeout: std::time::Duration,
}

/// --- output ---
#[derive(::core::default::Default, ::einstellung::serde::Deserialize)]
#[serde(crate = "::einstellung::serde")]
struct NetworkConfigPartial {
    host: ::core::option::Option<String>,
    port: ::core::option::Option<u16>,
    timeout: ::core::option::Option<std::time::Duration>,
}
#[automatically_derived]
impl ::einstellung::PartialConfig for NetworkConfigPartial {
    type Complete = NetworkConfig;
    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),
            timeout: next.timeout.or(self.timeout),
        })
    }
    fn build(
        self,
    ) -> ::core::result::Result<Self::Complete, ::einstellung::ConfigError> {
        ::core::result::Result::Ok(NetworkConfig {
            host: self.host.unwrap_or_else(|| "localhost".to_string()),
            port: self.port.unwrap_or(8080),
            timeout: self.timeout.unwrap_or_else(|| std::time::Duration::from_secs(30)),
        })
    }
}
#[automatically_derived]
impl ::einstellung::Config for NetworkConfig {
    type Partial = NetworkConfigPartial;
}