#conf #load #file #struct #config-toml #find

loadconf

Library for loading configuration files quickly

2 unstable releases

Uses old Rust 2015

0.2.0 Feb 11, 2018
0.1.2 Feb 10, 2018

#973 in Configuration

ISC license

14KB
222 lines

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");
}

Dependencies

~0.9–1.6MB
~32K SLoC