toml-config
Loads and decodes TOML files into Rust structures
Documentation
Examples
extern crate rustc_serialize;
extern crate toml_config;
use rustc_serialize::{Encodable, Decodable};
use std::path::Path;
use toml_config::ConfigFactory;
#[derive(RustcEncodable, RustcDecodable)]
struct Config {
nested: NestedConfig
}
impl Default for Config {
fn default() -> Config {
Config {
nested: NestedConfig::default()
}
}
}
#[derive(RustcEncodable, RustcDecodable)]
struct NestedConfig {
value: String,
values: Vec<u16>
}
impl Default for NestedConfig {
fn default() -> NestedConfig {
NestedConfig {
value: "default".to_owned(),
values: vec![0, 0, 0]
}
}
}
let config: Config = ConfigFactory::load(Path::new("config.toml"));
assert_eq!(config.nested.value, "test");
assert_eq!(config.nested.values, vec![1, 2, 3]);