pub struct Config { /* private fields */ }Expand description
The pencil Config type, We provide ways to fill it from JSON files:
let mut app = chilli::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 = chilli::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"Implementations§
Source§impl Config
impl Config
Sourcepub fn get(&self, key: &str) -> Option<&Value>
pub fn get(&self, key: &str) -> Option<&Value>
Returns a reference to the value corresponding to the key.
Sourcepub fn get_boolean(&self, key: &str, default: bool) -> bool
pub 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.
Sourcepub fn from_envvar(&mut self, variable_name: &str)
pub fn from_envvar(&mut self, variable_name: &str)
Loads a configuration from an environment variable pointing to a JSON configuration file.
Sourcepub fn from_jsonfile(&mut self, filepath: &str)
pub fn from_jsonfile(&mut self, filepath: &str)
Updates the values in the config from a JSON file.
Sourcepub fn from_object(&mut self, object: Map<String, Value>)
pub fn from_object(&mut self, object: Map<String, Value>)
Updates the values from the given Object.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more