Struct pencil::config::Config [] [src]

pub struct Config {
    // some fields omitted
}

The pencil Config type, We provide ways to fill it from JSON files:

let mut app = pencil::Pencil::new("/demo");
app.config.from_jsonfile("yourconfig.json")

You can also load configurations from an environment variable pointing to a file:

let mut app = pencil::Pencil::new("/demo");
app.config.from_envvar("YOURAPPLICATION_SETTINGS")

In this case, you have to set this environment variable to the file you want to use. On Linux and OS X you can use the export statement:

export YOURAPPLICATION_SETTINGS="/path/to/config/file"

Methods

impl Config
[src]

fn new() -> Config

Create a Config object.

fn set(&mut self, key: &str, value: Json)

Set a value for the key.

fn get(&self, key: &str) -> Option<&Json>

Returns a reference to the value corresponding to the key.

fn get_boolean(&self, key: &str, default: bool) -> bool

Get a boolean configuration value. If the key doesn't exist or the value is not a Json::Boolean, the default value will be returned.

fn from_envvar(&mut self, variable_name: &str)

Loads a configuration from an environment variable pointing to a JSON configuration file.

fn from_jsonfile(&mut self, filepath: &str)

Updates the values in the config from a JSON file.

fn from_object(&mut self, object: Object)

Updates the values from the given Object.

Trait Implementations

impl Clone for Config
[src]

fn clone(&self) -> Config

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)
1.0.0

Performs copy-assignment from source. Read more

impl Default for Config
[src]

fn default() -> Config

Returns the "default value" for a type. Read more

impl Debug for Config
[src]

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

Formats the value using the given formatter.