PartialConfig

Trait PartialConfig 

Source
pub trait PartialConfig:
    Clone
    + Default
    + DeserializeOwned
    + Schematic
    + Serialize
    + Sized {
    type Context: Default;

    // Required methods
    fn default_values(
        context: &Self::Context,
    ) -> Result<Option<Self>, ConfigError>;
    fn env_values() -> Result<Option<Self>, ConfigError>;
    fn extends_from(&self) -> Option<ExtendsFrom>;
    fn finalize(self, context: &Self::Context) -> Result<Self, ConfigError>;
    fn merge(
        &mut self,
        context: &Self::Context,
        next: Self,
    ) -> Result<(), ConfigError>;

    // Provided method
    fn validate(
        &self,
        context: &Self::Context,
        finalize: bool,
    ) -> Result<(), ConfigError> { ... }
}
Expand description

Represents a partial configuration of the base Config, with all settings marked as optional by wrapping the values in Option.

Required Associated Types§

Required Methods§

Source

fn default_values(context: &Self::Context) -> Result<Option<Self>, ConfigError>

Return a partial configuration with values populated with default values for settings marked with #[setting(default)]. Unmarked settings will be None.

If a default value fails to parse or cast into the correct type, an error is returned.

Source

fn env_values() -> Result<Option<Self>, ConfigError>

Return a partial configuration with values populated from environment variables for settings marked with #[setting(env)]. Unmarked settings will be None.

If an environment variable does not exist, the value will be None. If the variable fails to parse or cast into the correct type, an error is returned.

Source

fn extends_from(&self) -> Option<ExtendsFrom>

When a setting is marked as extendable with #[setting(extend)], this returns ExtendsFrom with the extended sources, either a list of strings or a single string. When no setting is extendable, this returns None.

Source

fn finalize(self, context: &Self::Context) -> Result<Self, ConfigError>

Finalize the partial configuration by consuming it and populating all fields with a value. Defaults values from PartialConfig::default_values will be applied first, followed by merging the current partial, and lastly environment variable values from PartialConfig::env_values.

Source

fn merge( &mut self, context: &Self::Context, next: Self, ) -> Result<(), ConfigError>

Merge another partial configuration into this one and clone values when applicable. The following merge strategies are applied:

  • Current None values are replaced with the next value if Some.
  • Current Some values are merged with the next value if Some, using the merge function from #[setting(merge)].

Provided Methods§

Source

fn validate( &self, context: &Self::Context, finalize: bool, ) -> Result<(), ConfigError>

Recursively validate the configuration with the provided context. Validation should be done on the final state, after merging partials.

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§