Trait confik::ConfigurationBuilder
source · 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§
sourcetype Target
type Target
The target that will be converted into. See Configuration
.
Required Methods§
sourcefn merge(self, other: Self) -> Self
fn merge(self, other: Self) -> Self
Combines two builders recursively, preferring self
’s data, if present.
sourcefn try_build(self) -> Result<Self::Target, Error>
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.
sourcefn contains_non_secret_data(&self) -> Result<bool, UnexpectedSecret>
fn contains_non_secret_data(&self) -> Result<bool, UnexpectedSecret>
Called recursively on each field, aiming to hit all SecretBuilder
s. 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§
Implementations on Foreign Types§
source§impl<T> ConfigurationBuilder for Option<T>where
T: DeserializeOwned + Configuration,
impl<T> ConfigurationBuilder for Option<T>where
T: DeserializeOwned + Configuration,
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>
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
fn merge(self, other: Self) -> Self
fn try_build(self) -> Result<Self::Target, Error>
source§impl<T> ConfigurationBuilder for PhantomData<T>
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.