[][src]Module spirit::cfg_loader

Configuration loading.

To load the configuration, multiple sources may need to be combined ‒ multiple files, directories with files, command line, environment variables... and may need to be reloaded during the lifetime of an application.

The Spirit object (and it's Builder) provide high-level semi-automagical management of that. If you do not want to have the full machinery of that, you can use this module to do the loading manually.

The lifetime of loading is:

  1. Create a Builder with Builder::new.
  2. Configure the it, using the methods on it.
  3. Parse the command line and prepare the loader with build (or, alternatively build_no_opts if command line should not be considered).
  4. Load (even as many times as needed) the configuration using load.


use serde::Deserialize;
use spirit::{AnyError, Empty};
use spirit::cfg_loader::Builder;

#[derive(Default, Deserialize)]
struct Cfg {
    message: String,

fn main() -> Result<(), AnyError> {
    let (Empty {}, mut loader) = Builder::new()
    let cfg: Cfg = loader.load()?;
    println!("{}", cfg.message);



A builder for the Loader.


An error returned whenever the user passes something not a file nor a directory as configuration.


The loader of configuration.


Returned if configuration path is missing.



Interface for configuring configuration loading options.