Reorder Map::retain to keep keys() and values() adjacent

This commit is contained in:
David Tolnay
2021-11-12 19:07:26 -08:00
parent 37da27fc77
commit 24f85d2ecf

View File

@@ -234,19 +234,6 @@ impl Map<String, Value> {
}
}
/// Retains only the elements specified by the predicate.
///
/// In other words, remove all pairs `(k, v)` such that `f(&k, &mut v)`
/// returns `false`.
#[cfg(not(no_btreemap_retain))]
#[inline]
pub fn retain<F>(&mut self, f: F)
where
F: FnMut(&String, &mut Value) -> bool,
{
self.map.retain(f);
}
/// Gets an iterator over the values of the map.
#[inline]
pub fn values(&self) -> Values {
@@ -262,6 +249,19 @@ impl Map<String, Value> {
iter: self.map.values_mut(),
}
}
/// Retains only the elements specified by the predicate.
///
/// In other words, remove all pairs `(k, v)` such that `f(&k, &mut v)`
/// returns `false`.
#[cfg(not(no_btreemap_retain))]
#[inline]
pub fn retain<F>(&mut self, f: F)
where
F: FnMut(&String, &mut Value) -> bool,
{
self.map.retain(f);
}
}
#[allow(clippy::derivable_impls)] // clippy bug: https://github.com/rust-lang/rust-clippy/issues/7655