pub trait Layer: for<'de> Deserialize<'de> {
// Required methods
fn empty() -> Self;
fn default_values() -> Self;
fn from_env() -> Result<Self, Error>;
fn with_fallback(self, fallback: Self) -> Self;
fn is_empty(&self) -> bool;
fn is_complete(&self) -> bool;
}Expand description
A configuration layer: all fields are optional. Can be directly deserialized
via serde.
Required Methods§
Sourcefn default_values() -> Self
fn default_values() -> Self
Returns an object containing all default values (i.e. set via
#[config(default = ...)] when deriving Config) with all remaining
values/fields set to None/being empty.
Sourcefn from_env() -> Result<Self, Error>
fn from_env() -> Result<Self, Error>
Loads values from environment variables. This is only relevant for
fields annotated with #[config(env = "...")]: all fields not
annotated env will be None.
If the env variable corresponding to a field is not set, that field is
None. If it is set and non-empty, but it failed to deserialize into
the target type, an error is returned. If set to an empty string and
if it fails to deserialize, it’s treated as not set.
Sourcefn with_fallback(self, fallback: Self) -> Self
fn with_fallback(self, fallback: Self) -> Self
Combines two layers. self has a higher priority; missing values in
self are filled with values in fallback, if they exist. The
semantics of this method is basically like in Option::or.
Sourcefn is_complete(&self) -> bool
fn is_complete(&self) -> bool
Returns true if all required (non-optional) values in this
configuration are set. If this returns true, Config::from_layer
will not return an error.
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.