Skip to content

Commit 7ee6cca

Browse files
committed
Refactor: use iterator methods over for loops
1 parent 6d0336b commit 7ee6cca

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

crates/vfs/src/loader.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,25 +155,23 @@ impl Directories {
155155
/// - This path is longer than any element in `self.exclude` that is a prefix
156156
/// of `path`. In case of equality, exclusion wins.
157157
fn includes_path(&self, path: &AbsPath) -> bool {
158-
let mut include: Option<&AbsPathBuf> = None;
159-
for incl in &self.include {
160-
if path.starts_with(incl) {
161-
include = Some(match include {
162-
Some(prev) if prev.starts_with(incl) => prev,
163-
_ => incl,
164-
})
158+
let include = self.include.iter().fold(None::<&AbsPathBuf>, |include, incl| {
159+
if !path.starts_with(incl) {
160+
return include;
165161
}
166-
}
162+
163+
Some(match include {
164+
Some(prev) if prev.starts_with(incl) => prev,
165+
_ => incl,
166+
})
167+
});
168+
167169
let include = match include {
168170
Some(it) => it,
169171
None => return false,
170172
};
171-
for excl in &self.exclude {
172-
if path.starts_with(excl) && excl.starts_with(include) {
173-
return false;
174-
}
175-
}
176-
true
173+
174+
!self.exclude.iter().any(|excl| path.starts_with(excl) && excl.starts_with(include))
177175
}
178176
}
179177

0 commit comments

Comments
 (0)