From 86635752af66104c503d9738ef18de6a07e5aafc Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sun, 20 Mar 2022 14:21:45 +0000 Subject: [PATCH] Also implement or_insert_with_key --- agb/src/hash_map.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/agb/src/hash_map.rs b/agb/src/hash_map.rs index 2b335f62..43078152 100644 --- a/agb/src/hash_map.rs +++ b/agb/src/hash_map.rs @@ -187,6 +187,19 @@ where } } + pub fn or_insert_with_key(self, f: F) + where + F: FnOnce(&K) -> V, + { + match self { + Entry::Occupied(_) => {} + Entry::Vacant(e) => { + let value = f(&e.key); + e.map.insert(e.key, value); + } + } + } + pub fn and_modify(self, f: F) -> Self where F: FnOnce(&mut V),