Hi All,
I'm building a yaml validator for my project and have now a number of variables from that yaml moving into various functions to check those values.
In on of those cases I have directory paths that need to be checked for specific file extensions (in one case this is "fasta.gz" and another is both "cram" and "crai" ). However, i've been using unwrap() and that errors out if the directory doesn't exist. How do i go about fixing it? My current code is:
if dtype == "pacbio" {
let data_files = fs::read_dir(&path).unwrap();
let files: Vec<PathBuf> = data_files.filter_map(|f| f.ok())
.filter(|d| match d.path().extension() {
None => false,
Some(ex) => ex == "fasta.gz"
})
.map(|f| f.path())
.collect();
println!("{:?}", &files);
}
I don't quite understand using unwrap_or or unwrap_or_else, i assumed them to kind of act like pass if true else print("oops") but clearly im wrong.
I've written this with some help from tutorials but I guess they expect there to only be cases where the dir exists.
Thanks in advance for any help!