Struct sharp_pencil::config::Config
source · [−]pub struct Config { /* private fields */ }
Expand description
The pencil Config
type, We provide ways to fill it from JSON files:
let mut app = sharp_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 = sharp_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"
Implementations
sourceimpl 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 RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more