rfcs icon indicating copy to clipboard operation
rfcs copied to clipboard

Add HashMap.entry_or_clone() method

Open dnspies opened this issue 10 years ago • 12 comments

Sometimes I have a key type which implements Clone, but for efficiency reasons I don't want to clone it unless it's absolutely necessary.

In this case it would be nice to have a method

my_hash_map.entry_or_clone(&k)

which behaves identically to

my_hash_map.entry(k.clone())

but only bothers to clone k if the key doesn't already exist in my_hash_map.

dnspies avatar Jul 11 '15 16:07 dnspies