pub fn load(filename: &str) -> Result<Config, Error> {
        let contents = match fs::read_to_string(filename) {
            Ok(contents) => contents,
            Err(error) if error.kind() == io::ErrorKind::NotFound => return Ok(Config::new()),
            Err(error) => return Err(Error::IOError(error)),
        };
        let config = match toml::from_str(&contents) {
            Ok(contents) => contents,
            Err(error) if error.line_col().is_some() => {
                return Err(Error::ParseError(ParseError {
                    filename: String::from(filename),
                    message: format!("{}", error),
                }));
            }
            Err(error) => return Err(Error::TomlDeError(error)),
        };
        log::info!("Loaded config from {}", filename);
        Ok(config)
    }
// If no file is found, returns default config instead of error
If no file is found, returns default config instead of error
If no file is found returns default config instead of error
pub fn load(filename: &str) -> Result<Config, Error> {
        let contents = match fs::read_to_string(filename) {
            Ok(contents) => contents,
            Err(error) if error.kind() == io::ErrorKind::NotFound => return Ok(Config::new()),
            Err(error) => return Err(Error::IOError(error)),
        };
        let config = match toml::from_str(&contents) {
            Ok(contents) => contents,
            Err(error) if error.line_col().is_some() => {
                return Err(Error::ParseError(ParseError {
                    filename: String::from(filename),
                    message: format!("{}", error),
                }));
            }
            Err(error) => return Err(Error::TomlDeError(error)),
        };
        log::info!("Loaded config from {}", filename);
        Ok(config)
    }
pub fn load ( filename : & str ) -> Result < Config , Error > { let contents = match fs :: read_to_string ( filename ) { Ok ( contents ) => contents , Err ( error ) if error . kind ( ) == io :: ErrorKind :: NotFound => return Ok ( Config :: new ( ) ) , Err ( error ) => return Err ( Error :: IOError ( error ) ) , } ; let config = match toml :: from_str ( & contents ) { Ok ( contents ) => contents , Err ( error ) if error . line_col ( ) . is_some ( ) => { return Err ( Error :: ParseError ( ParseError { filename : String :: from ( filename ) , message : format ! ( " " error ) , } ) ) ; } Err ( error ) => return Err ( Error :: TomlDeError ( error ) ) , } ; log :: info ! ( " " filename ) ; Ok ( config ) }
If no file is found, returns default config instead of error
If no file is found returns default config instead of error
filename
&str
filename
&str