[][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.

Examples

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

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

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

Structs

Builder

A builder for the Loader.

InvalidFileType

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

Loader

The loader of configuration.

MissingFile

Returned if configuration path is missing.

Traits

ConfigBuilder

Interface for configuring configuration loading options.