Closed caelunshun closed 2 years ago
If you address my comments in all three variants this seems like a nice addition.
We might get better code generation if we do
#[derive(Debug)]
enum Never { }
self.try_insert_with_key::<_, Never>(move |k| Ok(f(k))).unwrap()
Sounds good. I've addressed your comments and used the Never
trick.
Adds a new
try_insert_with_key
method toSlotMap
,DenseSlotMap
, andHopSlotMap
. This method accepts a closure returning aResult
. If the closure returns an error,try_insert_with_key
leaves the slotmap untouched and returns the error.This is useful when value construction is fallible.