From: Jeffrey Czyz Date: Tue, 12 Dec 2023 20:51:22 +0000 (-0600) Subject: Add IndexedMap::get_key_value X-Git-Tag: v0.0.123-beta~10^2~8 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=b783736356d17704852ea121a325b2978884ad9a;p=rust-lightning 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. --- diff --git a/lightning/src/util/indexed_map.rs b/lightning/src/util/indexed_map.rs index 4f694bd2b..97788ffe6 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 {