/// Parses the content of the file from a string.
Parses the content of the file from a string.
Parses the content of the file from a string .
fn parse(content: &str, path: &Path) -> Result<Self, Error> {
        let content = match toml::from_str(content) {
            Ok(toml::Value::Table(content)) => content,
            Ok(_) => {
                eprintln!(
                    "Failed to parse config file {}: Not a mapping.",
                    path.display()
                );
                return Err(Error);
            }
            Err(err) => {
                eprintln!(
                    "Failed to parse config file {}: {}",
                    path.display(), err
                );
                return Err(Error);
            }
        };
        let dir = if path.is_relative() {
            path.join(match env::current_dir() {
                Ok(dir) => dir,
                Err(err) => {
                    eprintln!(
                        "Fatal: Can't determine current directory: {}.",
                        err
                    );
                    return Err(Error);
                }
            }).parent().unwrap().into() // a file always has a parent
        }
        else {
            path.parent().unwrap().into()
        };
        Ok(ConfigFile {
            content,
            path: path.into(),
            dir
        })
    }
fn parse ( content : & str , path : & Path ) -> Result < Self , Error > { let content = match toml :: from_str ( content ) { Ok ( toml :: Value :: Table ( content ) ) => content , Ok ( _ ) => { eprintln ! ( " " path display ( ) ) ; return Err ( Error ) ; } Err ( err ) => { eprintln ! ( " " path display ( ) err ) ; return Err ( Error ) ; } } ; let dir = if path . is_relative ( ) { path . join ( match env :: current_dir ( ) { Ok ( dir ) => dir , Err ( err ) => { eprintln ! ( " " err ) ; return Err ( Error ) ; } } ) . parent ( ) . unwrap ( ) . into ( ) // a file always has a parent } else { path . parent ( ) . unwrap ( ) . into ( ) } ; Ok ( ConfigFile { content , path : path . into ( ) , dir } ) }
Parses the content of the file from a string.
Parses the content of the file from a string .
content
&str
path
&Path