use chaining instead loops for find_fortune_files
This commit is contained in:
parent
2ef42d31e2
commit
b0d889ce37
1 changed files with 12 additions and 19 deletions
|
@ -16,25 +16,18 @@ pub fn get_random_cookie() -> Option<Cookie> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_fortune_files() -> Vec<String> {
|
fn find_fortune_files() -> Vec<String> {
|
||||||
let locations = get_paths();
|
get_paths()
|
||||||
let mut all_files: Vec<String> = vec![];
|
.into_iter()
|
||||||
|
.map(|loc| path::Path::new(&loc).to_owned())
|
||||||
for loc in locations {
|
.filter(|loc| loc.exists())
|
||||||
let full_path = path::Path::new(&loc);
|
.filter_map(|full_path| fs::read_dir(full_path.canonicalize().unwrap()).ok())
|
||||||
if full_path.exists() {
|
.flat_map(|files| {
|
||||||
if let Ok(files) = fs::read_dir(full_path.canonicalize().unwrap()) {
|
files
|
||||||
for file in files {
|
.filter_map(|file| file.ok())
|
||||||
if let Ok(f) = file {
|
.map(|file| file.path().to_str().unwrap().to_owned())
|
||||||
if is_fortfile(&f.path().to_str().unwrap()) {
|
})
|
||||||
all_files.push(f.path().to_str().unwrap().to_owned());
|
.filter(|file_path| is_fortfile(file_path))
|
||||||
}
|
.collect::<Vec<_>>()
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
all_files
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_fortfile(path: &str) -> bool {
|
fn is_fortfile(path: &str) -> bool {
|
||||||
|
|
Loading…
Reference in a new issue