Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(toml): add Map::retain method #575

Merged
merged 2 commits into from Jul 3, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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, keep: F)
epage marked this conversation as resolved.
Show resolved Hide resolved
where
F: FnMut(&String, &mut Value) -> bool,
epage marked this conversation as resolved.
Show resolved Hide resolved
{
self.map.retain(keep);
}

/// 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