Expand description
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.
./{name}
./{name}.toml
./.{name}
./.{name}.toml
~/.{name}
~/.{name}.toml
~/.config/{name}
~/.config/{name}.toml
~/.config/{name}/config
~/.config/{name}/config.toml
/etc/.config/{name}
/etc/.config/{name}.toml
/etc/.config/{name}/config
/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.