loadconf

Crates.ioloadconf
lib.rsloadconf
version0.2.0
sourcesrc
created_at2018-02-10 05:55:05.345321
updated_at2018-02-11 12:09:59.680666
descriptionLibrary for loading configuration files quickly.
homepage
repositoryhttps://github.com/xurtis/loadconf
max_upload_size
id50440
size14,173
owners (github:tsanga:owners)

documentation

README

Crate Documentation Build Status

A simple library for loading configuration files from disk. All that's required is a struct with serde::Deserialize and Default implemented.

The configuration file is always assumed to be encoded in TOML format.

The library will load the first struct it finds in the following list:

  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

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;

    let config = Config::load("testcfg");
}
Commit count: 21

cargo fmt