From c4b6b97ccb808283cbe8ca98006bfdb98e21e4df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Haudebourg?= Date: Thu, 11 Nov 2021 14:00:55 +0100 Subject: [PATCH 1/2] Add `Map::get_key_value` method. --- src/map.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/map.rs b/src/map.rs index 716f12852..2cd5e56f9 100644 --- a/src/map.rs +++ b/src/map.rs @@ -94,6 +94,19 @@ impl Map { 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] + pub fn get_key_value(&self, key: &Q) -> Option<(&String, &Value)> + where + String: Borrow, + 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. From 1ae5566f01542a315199107e90a695e25adb9a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Haudebourg?= Date: Wed, 17 Nov 2021 14:21:56 +0100 Subject: [PATCH 2/2] Disable `get_key_value` with older Rust versions. --- src/map.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/map.rs b/src/map.rs index 2cd5e56f9..6d8afd70f 100644 --- a/src/map.rs +++ b/src/map.rs @@ -99,6 +99,7 @@ impl Map { /// 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(&self, key: &Q) -> Option<(&String, &Value)> where String: Borrow,