Skip to content

Commit

Permalink
refactor: use flatten() on iterator instead of if let
Browse files Browse the repository at this point in the history
  • Loading branch information
max397574 committed Feb 3, 2023
1 parent 55f7120 commit a0c1383
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ impl Iterator for RecursiveFileIterator {
if let Ok(metadata) = entry.metadata() {
if metadata.is_dir() {
if let Ok(dir) = read_dir(entry.path()) {
for sub_entry in dir {
if let Ok(sub_entry) = sub_entry {
self.stack.push(sub_entry);
}
for sub_entry in dir.flatten() {
self.stack.push(sub_entry);
}
}
}
Expand All @@ -82,10 +80,8 @@ fn main() {
format_file(&path, parser, &args);
} else if path.is_dir() {
let mut stack = Vec::new();
for subdir in read_dir(path).unwrap() {
if let Ok(subdir) = subdir {
stack.push(subdir);
}
for subdir in read_dir(path).unwrap().flatten() {
stack.push(subdir);
}
let rec_iterator = RecursiveFileIterator { stack };
for file in rec_iterator {
Expand Down

0 comments on commit a0c1383

Please sign in to comment.