Also implement or_insert_with_key

This commit is contained in:
Gwilym Kuiper 2022-03-20 14:21:45 +00:00
parent ab80f200e8
commit 86635752af

View file

@ -187,6 +187,19 @@ where
}
}
pub fn or_insert_with_key<F>(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<F>(self, f: F) -> Self
where
F: FnOnce(&mut V),