pub trait VecMore<T> {
fn move_to<F>(&mut self, to: &mut Vec<T>, f: F)
where
F: FnMut(&T) -> bool;
}
impl<T> VecMore<T> for Vec<T> {
fn move_to<F>(&mut self, to: &mut Vec<T>, mut f: F)
where
F: FnMut(&T) -> bool,
{
let len = self.len();
let mut del = 0;
{
let v = &mut **self;
for i in 0..len {
if f(&v[i]) {
del += 1;
} else if del > 0 {
v.swap(i - del, i);
}
}
}
if del > 0 {
while del > 0 {
let v = match self.pop() {
Some(v) => v,
None => break,
};
to.push(v);
del -= 1;
}
}
}
}