Skip to content

Commit ff65f5d

Browse files
committed
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.
1 parent f348496 commit ff65f5d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lightning/src/util/indexed_map.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ impl<K: Clone + Hash + Ord, V> IndexedMap<K, V> {
5858
self.map.get_mut(key)
5959
}
6060

61+
/// Fetches the key-value pair corresponding to the supplied key, if one exists.
62+
pub fn get_key_value(&self, key: &K) -> Option<(&K, &V)> {
63+
self.map.get_key_value(key)
64+
}
65+
6166
#[inline]
6267
/// Returns true if an element with the given `key` exists in the map.
6368
pub fn contains_key(&self, key: &K) -> bool {

0 commit comments

Comments
 (0)