Function ddmw_client::conf::load
source · pub fn load(fname: Option<&Path>) -> Result<Option<Figment>, Error>
Expand description
Load a DDMW application configuration file.
Attempt to load a configuration file in the following order:
- If
fname
hasSome
value, its value will be used. Otherwise: - If the environment variable
DDMW_APPCONF
is set, its value will be used. Otherwise: - The filename
ddmwapp.toml
, in the current working directory, will be used.
If none of these could be be found, Ok(None)
will be returned.
Example
Attempt to load a “hello.toml”, and return a default Config
buffer if
unsuccessful.
use std::path::Path;
use ddmw_client::conf::{Config, load};
use ddmw_client::Error;
fn get_conf() -> Result<Config, Error> {
let fname = Path::new("hello.toml");
let fig = load(Some(&fname))?.expect("Load failed");
let conf = fig.extract::<Config>()?;
Ok(conf)
}