Partial

Trait Partial 

Source
pub trait Partial: Default {
    type Target: HasPartial<Partial = Self>;
    type Error: Debug;

    // Required methods
    fn build(self) -> Result<Self::Target, Self::Error>;
    fn override_with(self, other: Self) -> Self;

    // Provided method
    fn source<T: Source<Self::Target>>(
        self,
        value: T,
    ) -> Result<Self, Self::Error>
       where <Self as Partial>::Error: From<<T as Source<<Self as Partial>::Target>>::Error> { ... }
}
Expand description

Implementors of this trait are considered partial states of the full configuration structure which is Partial::Target in this case. If you are implementing this trait manually, pay close attention to the documentation of the provided methods. If your partial structure contains Options only and is 1/1 correspondent to Partial::Target I would recommend either using the [partial_config::HasPartial] derive macro, or if you want to avoid using syn, to just cargo expand on the generated code and inline it.

Required Associated Types§

Source

type Target: HasPartial<Partial = Self>

The full configuration for which this type is considered a partial state obtained from a configuration layer.

Source

type Error: Debug

Error type returned from Partial::build, Partial::source and Partial::override_with. If in doubt, just use [partial_config::error::Error].

Required Methods§

Source

fn build(self) -> Result<Self::Target, Self::Error>

If at this point, all of the layers have been appropriately collected using the Partial::override_with, we have all of the information that we can obtain. We try to construct Partial::Target with the information that we have obtained from other sources, and report any missing fields. Keep in mind that the correct implementation should at least attempt to report all missing or malformed fields at once, instead of failing as soon as the first one is identified.

Source

fn override_with(self, other: Self) -> Self

If other contains values that are specified and different from self, or self is empty, replace the value with the other. Otherwise keep the one that is specified, so if self has a value specified, and other has None, keep the Some value.

Provided Methods§

Source

fn source<T: Source<Self::Target>>(self, value: T) -> Result<Self, Self::Error>
where <Self as Partial>::Error: From<<T as Source<<Self as Partial>::Target>>::Error>,

Obtain Self from an object that is known to be a Source of the appropriate partial configuraiton. You should not override this function, unless you want to change the reporting.

One thing to keep in mind is that the Partial::source function calls produce the overriding pattern in the exact order in which they are applied. So

PartialConfiguration::default().source(file).source(EnvVars).source(CliArgs)

shall read the file first, override any file specified in the file with the value specified in the environment variables and override any of those with the CLI arguments and not the reverse order.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§