[−][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:
- Create a
Builder
withBuilder::new
. - Configure the it, using the methods on it.
- Parse the command line and prepare the loader with
build
(or, alternativelybuild_no_opts
if command line should not be considered). - Load (even as many times as needed) the configuration using
load
.
Examples
use failure::Error; use serde::Deserialize; use spirit::Empty; use spirit::cfg_loader::Builder; #[derive(Default, Deserialize)] struct Cfg { #[serde(default)] message: String, } fn main() -> Result<(), Error> { let (Empty {}, mut loader) = Builder::new() .build(); let cfg: Cfg = loader.load()?; println!("{}", cfg.message); Ok(()) }
Structs
Builder | A builder for the |
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. |