Skip to content

Commit b783736

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 d85e0d6 commit b783736

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
@@ -56,6 +56,11 @@ impl<K: Clone + Hash + Ord, V> IndexedMap<K, V> {
5656
self.map.get_mut(key)
5757
}
5858

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

0 commit comments

Comments
 (0)