Crate ezconf[][src]

ezconf

A library to add configuration options to your project with as little boilerplate as possible. Uses toml as the configuration format.

All macros will cache the value for fast access times (Although, if it is really time critical, you should save it to a variable yourself)

Important: Due to the way this crate was implemented, it is necessary to import the lazy_static macro in your project

Example

#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate ezconf;

// You can specify multiple config files. Only the first one
// that can be opened will be used.
ezconf_file!(CONFIG = "tests/test.toml", "tests/test2.toml");

fn main() {
    let mut value = 100.0f64;
    // This is supposed to be a very complex algorithm
    for i in 0..1000 {
        // The default value (0.1) will be used if the value
        // does not exist in the config
        let CONSTANT = ezconf_float!(CONFIG: "float.a", 0.1);

        value = value.powf(CONSTANT);
    }
}

Re-exports

pub extern crate toml;
pub extern crate toml_query;

Macros

ezconf_bool

Read a boolean from the config

ezconf_file

Open a config file and store it in a static variable for easy access later on

ezconf_float

Read a float (f64) from the config

ezconf_int

Read an integer (i64) from the config

ezconf_str

Read a string (&str) from the config

ezconf_toml

Read a toml::Value from the config