(&mut self, f: F)
| 40 | |
| 41 | impl<T> Pluck<T> for Vec<T> { |
| 42 | fn pluck<R, F>(&mut self, f: F) -> Vec<R> |
| 43 | where |
| 44 | F: Fn(T) -> Result<R, T>, |
| 45 | { |
| 46 | let mut matched = Vec::new(); |
| 47 | let mut not_matched = Vec::new(); |
| 48 | |
| 49 | for transform in self.drain(..) { |
| 50 | match f(transform) { |
| 51 | Ok(t) => matched.push(t), |
| 52 | Err(transform) => not_matched.push(transform), |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | self.extend(not_matched); |
| 57 | matched |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /// Breaks up a [Vec] into two parts at the position of first matching element. |
no test coverage detected