Crate loadconf [] [src]

This library makes it simple to load configuration files from disk.

Configuration can be loaded into any struct that implements serde::Deserialize and std::default::Default.

The library will load the first struct it finds in the following list, falling back to the default if no files are found.

  1. ./{name}
  2. ./{name}.toml
  3. ./.{name}
  4. ./.{name}.toml
  5. ~/.{name}
  6. ~/.{name}.toml
  7. ~/.config/{name}
  8. ~/.config/{name}.toml
  9. ~/.config/{name}/config
  10. ~/.config/{name}/config.toml
  11. /etc/.config/{name}
  12. /etc/.config/{name}.toml
  13. /etc/.config/{name}/config
  14. /etc/.config/{name}/config.toml

Example Usage

#[macro_use]
extern crate serde_derive;
extern crate loadconf;

/// Sample configuration
#[derive(Deserialize)]
struct Config {
    /// Sample variable
    var: String,
}

impl Default for Config {
    fn default() -> Config {
        Config { var: "Test configuration.".to_string() }
    }
}

fn main() {
    use loadconf::Load;

    // Just search for configuration files
    let config = Config::load("sample");

    // Optionally use file specified on command line.
    use std::env;
    let mut args = env::args();
    args.next();
    let config = Config::fallback_load("sample", args.next());
}

Enums

Error

Errors produced when loading configuration.

Traits

Load

Load a struct from a configuration file.