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§

source

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::FileAccess if the file cannot be read.
  • Returns Error::<Format> if deserialization from file fails.

Provided Methods§

source

fn load(path: impl AsRef<Path>) -> Result<Self>
where Self: Sized,

Load config from path

§Errors
source

fn load_or_default(path: impl AsRef<Path>) -> Result<Self>
where Self: Sized + Default,

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::FileAccess if the file cannot be read by Permission denied or other failures.
  • Returns Error::UnsupportedFormat if the file extension is not supported.
  • Returns Error::<Format> if deserialization from file fails.

Implementors§