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] 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 716f128..2cd5e56 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.