Trait config_file2::LoadConfigFile
source · pub trait LoadConfigFile {
// Required method
fn load_with_specific_format(
path: impl AsRef<Path>,
config_type: ConfigFormat,
) -> Result<Self>
where Self: Sized;
// Provided methods
fn load(path: impl AsRef<Path>) -> Result<Self>
where Self: Sized { ... }
fn load_or_default(path: impl AsRef<Path>) -> Result<Self>
where Self: Sized + Default { ... }
}Expand description
Trait for loading a struct from a configuration file.
This trait is automatically implemented when serde::Deserialize is.
Required Methods§
sourcefn load_with_specific_format(
path: impl AsRef<Path>,
config_type: ConfigFormat,
) -> Result<Self>where
Self: Sized,
fn load_with_specific_format(
path: impl AsRef<Path>,
config_type: ConfigFormat,
) -> Result<Self>where
Self: Sized,
Load config from path with specific format, do not use extension to determine.
§Errors
- Returns
Error::FileAccessif the file cannot be read. - Returns
Error::<Format>if deserialization from file fails.
Provided Methods§
sourcefn load(path: impl AsRef<Path>) -> Result<Self>where
Self: Sized,
fn load(path: impl AsRef<Path>) -> Result<Self>where
Self: Sized,
Load config from path
§Errors
- Returns
Error::FileAccessif the file cannot be read. - Returns
Error::UnsupportedFormatif the file extension is not supported. - Returns
Error::<Format>if deserialization from file fails.
sourcefn load_or_default(path: impl AsRef<Path>) -> Result<Self>
fn load_or_default(path: impl AsRef<Path>) -> Result<Self>
Load config from path, if not found, use default instead
§Returns
- Returns the config loaded from file if the file exists, or default value if the file does not exist.
§Errors
- Returns
Error::FileAccessif the file cannot be read by Permission denied or other failures. - Returns
Error::UnsupportedFormatif the file extension is not supported. - Returns
Error::<Format>if deserialization from file fails.