Skip to content

Commit

Permalink
Small fixes and doc improvements. v3.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
xacrimon committed Feb 26, 2020
1 parent 110c10b commit 749c1da
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dashmap"
version = "3.5.0"
version = "3.5.1"
authors = ["Acrimon <[email protected]>"]
edition = "2018"
license = "MIT"
Expand Down
32 changes: 30 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl<'a, K: 'a + Eq + Hash, V: 'a, S: BuildHasher + Clone> DashMap<K, V, S> {
/// ```
/// use dashmap::DashMap;
///
/// let map = DashMap::with_capacity(2);
/// let map = DashMap::new();
/// map.insert("I am the key!", "And I am the value!");
/// ```
#[inline]
Expand All @@ -281,7 +281,7 @@ impl<'a, K: 'a + Eq + Hash, V: 'a, S: BuildHasher + Clone> DashMap<K, V, S> {
/// ```
/// use dashmap::DashMap;
///
/// let soccer_team = DashMap::with_capacity(2);
/// let soccer_team = DashMap::new();
/// soccer_team.insert("Jack", "Goalie");
/// assert_eq!(soccer_team.remove("Jack").unwrap().1, "Goalie");
/// ```
Expand All @@ -294,6 +294,34 @@ impl<'a, K: 'a + Eq + Hash, V: 'a, S: BuildHasher + Clone> DashMap<K, V, S> {
self._remove(key)
}

/// Removes an entry from the map, returning the key and value
/// if the entry existed and the provided conditional function returned true.
///
/// ```
/// use dashmap::DashMap;
///
/// let soccer_team = DashMap::new();
/// soccer_team.insert("Sam", "Forward");
/// soccer_team.remove_if("Sam", |_, position| position == &"Goalie");
/// assert!(soccer_team.contains_key("Sam"));
/// ```
/// ```
/// use dashmap::DashMap;
///
/// let soccer_team = DashMap::new();
/// soccer_team.insert("Sam", "Forward");
/// soccer_team.remove_if("Sam", |_, position| position == &"Forward");
/// assert!(!soccer_team.contains_key("Sam"));
/// ```
#[inline]
pub fn remove_if<Q>(&self, key: &Q, f: impl FnOnce(&K, &V) -> bool) -> Option<(K, V)>
where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
{
self._remove_if(key, f)
}

/// Creates an iterator over a DashMap yielding immutable references.
///
/// # Examples
Expand Down

0 comments on commit 749c1da

Please sign in to comment.