Simplify retain and retain_mut

This commit is contained in:
Ian Manske 2024-05-05 11:26:30 -04:00
parent 0efeaee6b1
commit c403581c0f

View File

@ -139,7 +139,7 @@ impl Record {
where where
F: FnMut(&str, &Value) -> bool, F: FnMut(&str, &Value) -> bool,
{ {
self.inner.retain(|(k, v)| keep(k, v)) self.retain_mut(|k, v| keep(k, v));
} }
/// Remove elements in-place that do not satisfy `keep` while allowing mutation of the value. /// Remove elements in-place that do not satisfy `keep` while allowing mutation of the value.
@ -183,10 +183,7 @@ impl Record {
where where
F: FnMut(&str, &mut Value) -> bool, F: FnMut(&str, &mut Value) -> bool,
{ {
self.inner = std::mem::take(&mut self.inner) self.inner.retain(|(k, v)| keep(k, v));
.into_iter()
.filter_map(|(col, mut val)| keep(&col, &mut val).then_some((col, val)))
.collect();
} }
/// Truncate record to the first `len` elements. /// Truncate record to the first `len` elements.