Function ddmw_util::app::load_conf[][src]

pub fn load_conf(fname: Option<&Path>) -> Result<Option<Config>, Error>

Load a DDMW application configuration file.

This function will attempt to load a configuration file in the following order:

  1. If fname is has Some value, that will be used. If fname is None:
  2. If the environment variable DDMW_APPCONF is set, its value will be used. If it is not set:
  3. 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”.

use std::path::Path;
use ddmw_util::app::{Config, load_conf};
use ddmw_util::Error;
fn get_conf() -> Result<Config, Error> {
  let fname = Path::new("hello.toml");
  Ok(load_conf(Some(&fname))?.unwrap_or_default())
}