Improve the search_for utilty function and reduce the nested code

This commit is contained in:
Anas Elgarhy 2023-02-08 21:30:31 +02:00
parent a5dd196937
commit c71992fc52
No known key found for this signature in database
GPG key ID: 0501802A1D496528
2 changed files with 11 additions and 12 deletions

View file

@ -2,6 +2,7 @@
mod arguments;
mod cmus;
mod utils;
use clap::Parser;

View file

@ -11,8 +11,8 @@ pub fn search_for(
) -> std::io::Result<Option<String>> {
// Search in the track directory.
for entry in std::fs::read_dir(search_directory)? {
if let Ok(entry) = entry {
if let Ok(file_type) = entry.file_type() {
let Ok(entry) = entry else { continue; };
let Ok(file_type) = entry.file_type() else { continue; };
if file_type.is_file() {
let Ok(file_name) = entry.file_name().into_string() else { continue; };
// Check if the file name matches any of the regular expressions.
@ -23,8 +23,6 @@ pub fn search_for(
}
}
}
}
}
// If the max depth is reached, return `None`.
if max_depth == 0 {
Ok(None)