Skip to content

Commit

Permalink
add Map::retain method
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospb19 committed Jun 28, 2023
1 parent 8fa9995 commit 2b247a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Add `Map::retain` method ([#460](https://github.com/ron-rs/ron/pull/460))
- Add CIFuzz GitHub action
- Fix issues [#277](https://github.com/ron-rs/ron/issues/277) and [#405](https://github.com/ron-rs/ron/issues/405) with `Value::Map` `IntoIter` and extraneous item check for `Value::Seq` ([#406](https://github.com/ron-rs/ron/pull/406))
- Fix issue [#401](https://github.com/ron-rs/ron/issues/401) with correct raw struct name identifier parsing ([#402](https://github.com/ron-rs/ron/pull/402))
Expand Down
13 changes: 13 additions & 0 deletions src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ impl Map {
pub fn values_mut(&mut self) -> impl Iterator<Item = &mut Value> + DoubleEndedIterator {
self.0.values_mut()
}

/// 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.
pub fn retain<F>(&mut self, keep: F)
where
F: FnMut(&Value, &mut Value) -> bool,
{
self.0.retain(keep);
}
}

impl FromIterator<(Value, Value)> for Map {
Expand Down

0 comments on commit 2b247a6

Please sign in to comment.