Skip to content

Commit

Permalink
Merge pull request #821 from timothee-haudebourg/get_key_value
Browse files Browse the repository at this point in the history
Add `Map::get_key_value` method.
  • Loading branch information
dtolnay committed Nov 17, 2021
2 parents a050481 + 1ae5566 commit 584f476
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/map.rs
Expand Up @@ -94,6 +94,20 @@ impl Map<String, Value> {
self.map.get_mut(key)
}

/// Returns the key-value pair matching the given key.
///
/// The key may be any borrowed form of the map's key type, but the ordering
/// on the borrowed form *must* match the ordering on the key type.
#[inline]
#[cfg(any(feature = "preserve_order", not(no_btreemap_get_key_value)))]
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&String, &Value)>
where
String: Borrow<Q>,
Q: ?Sized + Ord + Eq + Hash,
{
self.map.get_key_value(key)
}

/// Inserts a key-value pair into the map.
///
/// If the map did not have this key present, `None` is returned.
Expand Down

0 comments on commit 584f476

Please sign in to comment.