the.bay.news

Adding retain_unsorted or similar

Rust Internals
Adding retain_unsorted or similar
Just thought it was odd that there was no retain equivalent that uses swap_remove under the hood. Why not add something like this? fn retain_unordered<T, F>(vec: &mut Vec<T>, mut keep: F) where F: FnMut(&T) -> bool, { let mut i = 0; while i < vec.len() { if keep(&vec[i]) { i += 1; } else { vec.swap_remove(i); } } } Thank you for your time.

0 comments

Sign in to join the discussion — your thebay.events account works here.

No comments yet.