From b783736356d17704852ea121a325b2978884ad9a Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Tue, 12 Dec 2023 14:51:22 -0600 Subject: [PATCH 1/1] Add IndexedMap::get_key_value Useful for applying Option::map when needing both the key and value for when needing a reference to the key with a longer lifetime. --- lightning/src/util/indexed_map.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lightning/src/util/indexed_map.rs b/lightning/src/util/indexed_map.rs index 4f694bd2..97788ffe 100644 --- a/lightning/src/util/indexed_map.rs +++ b/lightning/src/util/indexed_map.rs @@ -56,6 +56,11 @@ impl IndexedMap { self.map.get_mut(key) } + /// Fetches the key-value pair corresponding to the supplied key, if one exists. + pub fn get_key_value(&self, key: &K) -> Option<(&K, &V)> { + self.map.get_key_value(key) + } + #[inline] /// Returns true if an element with the given `key` exists in the map. pub fn contains_key(&self, key: &K) -> bool { -- 2.30.2