Skip to main content

Loader

Trait Loader 

Source
pub trait Loader {
    // Required methods
    fn load_section<T>(&self, key: &str) -> Result<T, ConfigError>
       where T: DeserializeOwned + Default;
    fn validate(&self) -> Result<(), ConfigError>;
}
Expand description

Load typed TOML sections from a layered config chain.

Implementations merge config directories in order (later wins) and return Ok(T::default()) when the requested key is absent from every source. Environment variable substitution ({{VAR_NAME}} syntax) is optionally supported when the loader was created with a SubstitutionPolicy.

The reference implementation is DefaultLoader. This trait is in scope for generic code that accepts any loader.

Required Methods§

Source

fn load_section<T>(&self, key: &str) -> Result<T, ConfigError>

Load the section at key (dotted path, e.g. "outer.inner") from all configured directories, merging with last-wins semantics.

Returns Ok(T::default()) when the key is absent from every file. If the loader was created with a substitution policy, {{VAR_NAME}} placeholders are substituted with environment variable values after loading.

Source

fn validate(&self) -> Result<(), ConfigError>

Validate that all configured directories are accessible.

Non-existent paths are permitted (skipped at load time); a path that exists but is not a directory is a hard error.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§