Struct config::types::Config [] [src]

pub struct Config {
    // some fields omitted
}

The top-level Config type that represents a configuration

Methods

impl Config
[src]

fn new(sl: SettingsList) -> Config

Creates a new wrapper Config to hold a SettingsList

fn lookup(&self, path: &str) -> Option<&Value>

Looks up a value in a configuration. A path is a dot-separated list of settings describing the path of the desired value in the configuration. Returns None if the path is invalid. A path is invalid if it is not syntactically well-formed, if it attempts to index an array or list beyond the limit, or if it includes an unknown setting.

Examples

Suppose we have loaded a configuration that consists of:

my_string = "hello";
a_list = ([1, 2, 3], true, { x = 4; }, "good bye");

Then, the path to retrieve "hello" is my_string. The path to retrieve true inside a_list would be a_list.[1]. The path to retrieve the setting x inside a_list would be alist.[2].x.

Here's a small demonstration:

use config::reader::from_str;

let my_conf = from_str("my_string = \"hello\"; a_list = ([1, 2, 3], true, { x = 4; }, \"good_bye\");").unwrap();

let my_str_value = my_conf.lookup("my_string");
assert!(my_str_value.is_some());

let my_boolean_value = my_conf.lookup("a_list.[1]");
assert!(my_boolean_value.is_some());

let my_x_setting = my_conf.lookup("a_list.[2].x");
assert!(my_x_setting.is_some());

fn lookup_boolean(&self, path: &str) -> Option<bool>

A convenient wrapper around lookup() that unwraps the underlying primitive type of a generic Value.

Returns None in the same way lookup() does; or if the underlying Value type does not match with the requested type - in this case, bool.

fn lookup_integer32(&self, path: &str) -> Option<i32>

A convenient wrapper around lookup() that unwraps the underlying primitive type of a generic Value.

Returns None in the same way lookup() does; or if the underlying Value type does not match with the requested type - in this case, i32.

fn lookup_integer64(&self, path: &str) -> Option<i64>

A convenient wrapper around lookup() that unwraps the underlying primitive type of a generic Value.

Returns None in the same way lookup() does; or if the underlying Value type does not match with the requested type - in this case, i64.

fn lookup_floating32(&self, path: &str) -> Option<f32>

A convenient wrapper around lookup() that unwraps the underlying primitive type of a generic Value.

Returns None in the same way lookup() does; or if the underlying Value type does not match with the requested type - in this case, f32.

fn lookup_floating64(&self, path: &str) -> Option<f64>

A convenient wrapper around lookup() that unwraps the underlying primitive type of a generic Value.

Returns None in the same way lookup() does; or if the underlying Value type does not match with the requested type - in this case, f64.

fn lookup_str(&self, path: &str) -> Option<&str>

A convenient wrapper around lookup() that unwraps the underlying primitive type of a generic Value.

Returns None in the same way lookup() does; or if the underlying Value type does not match with the requested type - in this case, String.

fn lookup_boolean_or(&self, path: &str, default: bool) -> bool

A convenient wrapper around lookup_boolean() that unwraps the underlying primitive type of a boolean Value.

If either of lookup_boolean() or lookup return None, then the user-provided default value is returned.

fn lookup_integer32_or(&self, path: &str, default: i32) -> i32

A convenient wrapper around lookup_integer32() that unwraps the underlying primitive type of an integer32 Value.

If either of lookup_integer32() or lookup return None, then the user-provided default value is returned.

fn lookup_integer64_or(&self, path: &str, default: i64) -> i64

A convenient wrapper around lookup_integer64() that unwraps the underlying primitive type of an integer64 Value.

If either of lookup_integer64() or lookup return None, then the user-provided default value is returned.

fn lookup_floating32_or(&self, path: &str, default: f32) -> f32

A convenient wrapper around lookup_floating32() that unwraps the underlying primitive type of an floating32 Value.

If either of lookup_floating32() or lookup return None, then the user-provided default value is returned.

fn lookup_floating64_or(&self, path: &str, default: f64) -> f64

A convenient wrapper around lookup_floating64() that unwraps the underlying primitive type of an floating64 Value. If either of lookup_floating64() or lookup return None, then the user-provided default value is returned.

fn lookup_str_or<'a>(&'a self, path: &str, default: &'a str) -> &'a str

A convenient wrapper around lookup_str() that unwraps the underlying primitive type of a string Value.

If either of lookup_str() or lookup return None, then the user-provided default value is returned.

Trait Implementations

impl PartialEq for Config
[src]

fn eq(&self, __arg_0: &Config) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, __arg_0: &Config) -> bool

This method tests for !=.

impl Debug for Config
[src]

fn fmt(&self, __arg_0: &mut Formatter) -> Result

Formats the value using the given formatter.

impl FromStr for Config
[src]

type Err = ConfigError

The associated error which can be returned from parsing.

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more