Struct universal_config::ConfigLoader
source · pub struct ConfigLoader<'a> { /* private fields */ }Expand description
Config
Implementations§
source§impl<'a> ConfigLoader<'a>
impl<'a> ConfigLoader<'a>
sourcepub const fn new(app_name: &'a str) -> ConfigLoader<'a>
pub const fn new(app_name: &'a str) -> ConfigLoader<'a>
Creates a new config loader for the provided app name. Uses a default file name of “config” and all formats.
sourcepub fn with_file_name(&mut self, file_name: &'a str) -> &Self
pub fn with_file_name(&mut self, file_name: &'a str) -> &Self
Specifies the file name to look for, excluding the extension.
If not specified, defaults to “config”.
sourcepub fn with_formats(&mut self, formats: &'a [Format]) -> &Self
pub fn with_formats(&mut self, formats: &'a [Format]) -> &Self
Specifies which file formats to search for, and in which order.
If not specified, all formats are checked for in the order JSON, YAML, TOML, Corn.
sourcepub fn with_config_dir(&mut self, dir: &'a str) -> &Self
pub fn with_config_dir(&mut self, dir: &'a str) -> &Self
Specifies which directory the config should be loaded from.
If not specified, loads from $XDG_CONFIG_DIR/<app_name>
or $HOME/.<app_name> if the config dir does not exist.
sourcepub fn find_and_load<T: DeserializeOwned>(&self) -> Result<T, UniversalConfig>
pub fn find_and_load<T: DeserializeOwned>(&self) -> Result<T, UniversalConfig>
Attempts to locate a config file on disk and load it.
Errors
Will return a UniversalConfigError if any error occurs
when looking for, reading, or deserializing a config file.
sourcepub fn load<T: DeserializeOwned, P: AsRef<Path>>(
path: P
) -> Result<T, UniversalConfig>
pub fn load<T: DeserializeOwned, P: AsRef<Path>>( path: P ) -> Result<T, UniversalConfig>
Loads the file at the given path,
deserializing it into a new T.
The type is automatically determined from the file extension.
Errors
Will return a UniversalConfigError if unable to read or deserialize the file.