pub fn load<T: Serialize + DeserializeOwned + Default>(name: &str) -> Result<T, ConfyError> {
    let root_name = get_root_name()?;

    let project = ProjectDirs::from("rs", &root_name, name);

    let config_dir_str = get_configuration_directory_str(&project)?;

    let path: PathBuf = [config_dir_str, &format!("{}.toml", name)].iter().collect();

    match File::open(&path) {
        Ok(mut cfg) => {
            let cfg_string = cfg
                .get_string()
                .map_err(ConfyError::ReadConfigurationFileError)?;
            let cfg_data = toml::from_str(&cfg_string);
            cfg_data.map_err(ConfyError::BadTomlData)
        }
        Err(ref e) if e.kind() == NotFound => {
            fs::create_dir_all(project.config_dir())
                .map_err(ConfyError::DirectoryCreationFailed)?;
            store(name, T::default())?;
            Ok(T::default())
        }
        Err(e) => Err(ConfyError::GeneralLoadError(e)),
    }
}
/// Load an application configuration from disk
///
/// A new configuration file is created with default values if none
/// exists.
///
/// Errors that are returned from this function are I/O related,
/// for example if the writing of the new configuration fails
/// or `confy` encounters an operating system or environment
/// that it does not support.
///
/// **Note:** The type of configuration needs to be declared in some way
/// that is inferrable by the compiler. Also note that your
/// configuration needs to implement `Default`.
///
/// ```rust,no_run
/// # struct MyConfig {}
/// # impl ::std::default::Default for MyConf {
/// #     fn default() -> Self { Self {} }
/// # }
/// let cfg: MyConfig = confy::load("my-app")?;
/// ```
Load an application configuration from disk
A new configuration file is created with default values if none
exists.

Errors that are returned from this function are I/O related,
for example if the writing of the new configuration fails
or `confy` encounters an operating system or environment
that it does not support.

The type of configuration needs to be declared in some way
that is inferrable by the compiler. Also note that your
configuration needs to implement `Default`.


Load an application configuration from disk A new configuration file is created with default values if none exists . Errors that are returned from this function are I / O related for example if the writing of the new configuration fails or ` confy ` encounters an operating system or environment that it does not support . The type of configuration needs to be declared in some way that is inferrable by the compiler . Also note that your configuration needs to implement ` Default ` .
pub fn load<T: Serialize + DeserializeOwned + Default>(name: &str) -> Result<T, ConfyError> {
    let root_name = get_root_name()?;
    let project = ProjectDirs::from("rs", &root_name, name);
    let config_dir_str = get_configuration_directory_str(&project)?;
    let path: PathBuf = [config_dir_str, &format!("{}.toml", name)].iter().collect();
    match File::open(&path) {
        Ok(mut cfg) => {
            let cfg_string = cfg
                .get_string()
                .map_err(ConfyError::ReadConfigurationFileError)?;
            let cfg_data = toml::from_str(&cfg_string);
            cfg_data.map_err(ConfyError::BadTomlData)
        }
        Err(ref e) if e.kind() == NotFound => {
            fs::create_dir_all(project.config_dir())
                .map_err(ConfyError::DirectoryCreationFailed)?;
            store(name, T::default())?;
            Ok(T::default())
        }
        Err(e) => Err(ConfyError::GeneralLoadError(e)),
    }
}
pub fn load < T : Serialize + DeserializeOwned + Default > ( name : & str ) -> Result < T , ConfyError > { let root_name = get_root_name ( ) ? ; let project = ProjectDirs :: from ( " " , & root_name , name ) ; let config_dir_str = get_configuration_directory_str ( & project ) ? ; let path : PathBuf = [ config_dir_str , & format ! ( " " name ) ] . iter ( ) . collect ( ) ; match File :: open ( & path ) { Ok ( mut cfg ) => { let cfg_string = cfg . get_string ( ) . map_err ( ConfyError :: ReadConfigurationFileError ) ? ; let cfg_data = toml :: from_str ( & cfg_string ) ; cfg_data . map_err ( ConfyError :: BadTomlData ) } Err ( ref e ) if e . kind ( ) == NotFound => { fs :: create_dir_all ( project . config_dir ( ) ) . map_err ( ConfyError :: DirectoryCreationFailed ) ? ; store ( name , T :: default ( ) ) ? ; Ok ( T :: default ( ) ) } Err ( e ) => Err ( ConfyError :: GeneralLoadError ( e ) ) , } }
Load an application configuration from disk
A new configuration file is created with default values if none
exists.
Load an application configuration from disk A new configuration file is created with default values if none exists .
name
&str
struct myconfig {}
None
impl ::std::default::default for myconf {
None
fn default() -> self { self {} }
None
}
let cfg: MyConfig = confy::load("my-app")?;
```
let cfg : MyConfig = confy :: load ( " my - app " ) ? ; ` ` `