Skip to content

Commit 584f476

Browse files
authored
Merge pull request #821 from timothee-haudebourg/get_key_value
Add `Map::get_key_value` method.
2 parents a050481 + 1ae5566 commit 584f476

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/map.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ impl Map<String, Value> {
9494
self.map.get_mut(key)
9595
}
9696

97+
/// Returns the key-value pair matching the given key.
98+
///
99+
/// The key may be any borrowed form of the map's key type, but the ordering
100+
/// on the borrowed form *must* match the ordering on the key type.
101+
#[inline]
102+
#[cfg(any(feature = "preserve_order", not(no_btreemap_get_key_value)))]
103+
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&String, &Value)>
104+
where
105+
String: Borrow<Q>,
106+
Q: ?Sized + Ord + Eq + Hash,
107+
{
108+
self.map.get_key_value(key)
109+
}
110+
97111
/// Inserts a key-value pair into the map.
98112
///
99113
/// If the map did not have this key present, `None` is returned.

0 commit comments

Comments
 (0)