fn open_file(path: &Path, create_if_req: bool) -> File {
    match File::open(path) {
        Ok(file) => file,
        Err(err) => match err.kind() {
            ErrorKind::NotFound => {
                if create_if_req {
                    match File::create(path) {
                        Ok(file) => file,
                        Err(err) => {
                            eprintln!(
                                "       {} Unable to create file {}. Reason: {}",
                                Red.paint("error"),
                                path.to_str().unwrap(),
                                err.to_string()
                            );
                            process::exit(1);
                        }
                    }
                } else {
                    eprintln!(
                        "       {} File {} not found",
                        Red.paint("error"),
                        path.to_str().unwrap()
                    );
                    process::exit(2);
                }
            }
            _ => {
                eprintln!(
                    "       {} Unable to open file {}. Reason: {}",
                    Red.paint("error"),
                    path.to_str().unwrap(),
                    err.to_string()
                );
                process::exit(1);
            }
        },
    }
}
/// Opens and returns the file from [path].
Opens and returns the file from [path].
Opens and returns the file from [ path ] .
fn open_file(path: &Path, create_if_req: bool) -> File {
    match File::open(path) {
        Ok(file) => file,
        Err(err) => match err.kind() {
            ErrorKind::NotFound => {
                if create_if_req {
                    match File::create(path) {
                        Ok(file) => file,
                        Err(err) => {
                            eprintln!(
                                "       {} Unable to create file {}. Reason: {}",
                                Red.paint("error"),
                                path.to_str().unwrap(),
                                err.to_string()
                            );
                            process::exit(1);
                        }
                    }
                } else {
                    eprintln!(
                        "       {} File {} not found",
                        Red.paint("error"),
                        path.to_str().unwrap()
                    );
                    process::exit(2);
                }
            }
            _ => {
                eprintln!(
                    "       {} Unable to open file {}. Reason: {}",
                    Red.paint("error"),
                    path.to_str().unwrap(),
                    err.to_string()
                );
                process::exit(1);
            }
        },
    }
}
fn open_file ( path : & Path , create_if_req : bool ) -> File { match File :: open ( path ) { Ok ( file ) => file , Err ( err ) => match err . kind ( ) { ErrorKind :: NotFound => { if create_if_req { match File :: create ( path ) { Ok ( file ) => file , Err ( err ) => { eprintln ! ( " " Red paint ( " " ) path to_str ( ) unwrap ( ) err to_string ( ) ) ; process :: exit ( 1 ) ; } } } else { eprintln ! ( " " Red paint ( " " ) path to_str ( ) unwrap ( ) ) ; process :: exit ( 2 ) ; } } _ => { eprintln ! ( " " Red paint ( " " ) path to_str ( ) unwrap ( ) err to_string ( ) ) ; process :: exit ( 1 ) ; } } , } }
Opens and returns the file from [path].
Opens and returns the file from [ path ] .
path
&Path
create_if_req
bool
path
&Path
create_if_req
bool