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");

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

let mut app = pencil::Pencil::new("/demo");

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"


impl Config

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

fn clone(&self) -> Config

Returns a copy of the value. Read more

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

Performs copy-assignment from source. Read more

impl Default for Config

fn default() -> Config

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

impl Debug for Config

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

Formats the value using the given formatter.