[−][src]Function justconfig::sources::text::stack_config
pub fn stack_config(
config: &mut Config,
config_path: Option<&mut ConfPath>,
file_name: &OsString,
paths: &[&Path]
) -> Result<(), Error>
Helper function for config file stacking.
This function is a helper to allow searching for a configuration file in
multiple directories. Often a default configuration is supplied by the
distribution within /usr/share/mypackage
and the administrator can
override some settings by supplying a configuration file in /etc
. Maybe
even the user should be able to change some configuration options by having
a third configuration file within its home directory.
This helper function searches the given list of paths in the supplied order
and adds every configuration file as a configuration source. That way the
configuration files are merged by the rules stated in
addSource
.
The config_path
parameter allows you to borrow a
ConfPath
instance to the function. This instnace
will be used to store all configuration values for enumeration. See
Enumerating keys for details.
Example
// Define the search path. let paths: [&Path; 3] = [ &Path::new("/usr/share/myapp/etc"), &Path::new("/etc"), &Path::new(env!("HOME")).join(".config").join("myapp") ]; let mut config = Config::default(); stack_config(&mut config, None, &OsString::from("myapp.conf"), &paths[..]).unwrap();