Struct ezconf::config::Config

source ·
pub struct Config(_);
Expand description

A configuration

Can be used as global (but don’t forget to initialize it somewhere!):

static CONFIG: ezconf::Config = ezconf::INIT;

Implementations§

Initialize this configuration.

Can only be called once, further calls will return Err(()).

sources should be an iterator of possible config sources that are tried in order. The first one to load successfully will be used. If none of them load, an empty default config will be used and false is returned.

Example
static CONFIG: ezconf::Config = ezconf::INIT;

fn main() {
    CONFIG.init([ezconf::Source::File("config.toml")].iter()).unwrap();
}

Retrieve a value from this config.

Returns the value or None if it doesn’t exist.

Example
static CONFIG: ezconf::Config = ezconf::INIT;

fn main() {
    CONFIG.init([ezconf::Source::File("tests/test.toml")].iter()).unwrap();

    let v = CONFIG.get::<f32>("float.a").unwrap();
    assert_eq!(v, 1.4142135);
}

Retrieve a value from this config or return a default.

Returns the value or def if it doesn’t exist.

Example
static CONFIG: ezconf::Config = ezconf::INIT;

fn main() {
    CONFIG.init([ezconf::Source::File("tests/test.toml")].iter()).unwrap();

    let v = CONFIG.get_or::<String>("string.foobar", "somestring".into());
    assert_eq!(v, "somestring");
}

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.