pub trait ConfigurationBuilder: Default + DeserializeOwned {
    type Target;

    // Required methods
    fn merge(self, other: Self) -> Self;
    fn try_build(self) -> Result<Self::Target, Error>;
    fn contains_non_secret_data(&self) -> Result<bool, UnexpectedSecret>;
}
Expand description

A builder for a multi-source config deserialization.

This will almost never be implemented manually, instead being derived.

Builders must implement Default so that if the structure is nested in another then it being missing is not an error. For trivial cases, this is solved by using an Option<Configuration>. See the worked example on Configuration.

Required Associated Types§

source

type Target

The target that will be converted into. See Configuration.

Required Methods§

source

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

Combines two builders recursively, preferring self’s data, if present.

source

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

This will probably delegate to TryInto but allows it to be implemented for types foreign to the library.

source

fn contains_non_secret_data(&self) -> Result<bool, UnexpectedSecret>

Called recursively on each field, aiming to hit all SecretBuilders. This is only called when Source::allows_secrets is false.

If any data is present then Ok(true) is returned, unless the data is wrapped in a SecretBuilder in which case UnexpectedSecret is passed, which will then be built into the path to the secret data.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T> ConfigurationBuilder for Option<T>

Implementations for trivial types via Option.

This can also be used for user types, such as an enum with no variants containing fields. See the worked example on Configuration.

source§

fn contains_non_secret_data(&self) -> Result<bool, UnexpectedSecret>

Should not have an Option wrapping a secret as <Option<T> as ConfigurationBuilder is used for terminal types, therefore the SecretBuilder wrapping would be external to it.

§

type Target = T

source§

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

source§

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

source§

impl<T> ConfigurationBuilder for PhantomData<T>

PhantomData does not need a builder, however we cannot use () as that would make T unconstrained. Instead just making it use itself as a builder and rely on serde handling it alright.

§

type Target = PhantomData<T>

source§

fn merge(self, _other: Self) -> Self

source§

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

source§

fn contains_non_secret_data(&self) -> Result<bool, UnexpectedSecret>

source§

impl<T, const N: usize> ConfigurationBuilder for [T; N]

Implementors§