Skip to content

Commit

Permalink
feat(toml): add Map::retain method (#575)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospb19 committed Jul 3, 2023
1 parent 22fb58e commit bb108a8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/toml/src/map.rs
Expand Up @@ -138,6 +138,20 @@ impl Map<String, Value> {
self.map.remove(key)
}

/// Retains only the elements specified by the `keep` predicate.
///
/// In other words, remove all pairs `(k, v)` for which `keep(&k, &mut v)`
/// returns `false`.
///
/// The elements are visited in iteration order.
#[inline]
pub fn retain<F>(&mut self, mut keep: F)
where
F: FnMut(&str, &mut Value) -> bool,
{
self.map.retain(|key, value| keep(key.as_str(), value));
}

/// Gets the given key's corresponding entry in the map for in-place
/// manipulation.
pub fn entry<S>(&mut self, key: S) -> Entry<'_>
Expand Down

0 comments on commit bb108a8

Please sign in to comment.