Skip to content

Commit

Permalink
Fix MSRV: Remove use of Vec::retain_mut
Browse files Browse the repository at this point in the history
And replace that with our own implementation of `retain_unordered_mut`
which is usable under any rust version after v1.0

Signed-off-by: Jiahao XU <[email protected]>
  • Loading branch information
NobodyXu committed Oct 21, 2023
1 parent 4f9866e commit 2adc336
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ impl Build {
}

// Try waiting on them.
pendings.retain_mut(|(cmd, program, child, token)| {
retain_unordered_mut(&mut pendings, |(cmd, program, child, token)| {
match try_wait_on_child(cmd, program, &mut child.0, &mut stdout) {
Ok(Some(())) => {
// Task done, remove the entry
Expand Down Expand Up @@ -4127,3 +4127,19 @@ impl Drop for PrintThread {
self.handle.take().unwrap().join().unwrap();
}
}

/// Remove all element in `vec` which `f(element)` returns `false`.
#[cfg(feature = "parallel")]
fn retain_unordered_mut<T, F>(vec: &mut Vec<T>, mut f: F)
where
F: FnMut(&mut T) -> bool,
{
let mut i = 0;
while i < vec.len() {
if f(&mut vec[i]) {
i += 1;
} else {
vec.swap_remove(i);
}
}
}

0 comments on commit 2adc336

Please sign in to comment.