`entry2` documentation makes incorrect claim
apasel422 opened this issue · comments
Andrew Paseltiner commented
The following claim is incorrect:
Only copies the key if a new entry is inserted.
In particular, search_entry_hashed2
calls IntoCow::into_owned
if the key is not found, even if VacantEntry::insert
is not called. Ideally, VacantEntry
would be changed to delay copying until insert
is called.
Andrew Paseltiner commented
@gankro Any ideas on how we can do this most flexibly? I'm struggling to come up with a set of bounds that maintains the above while also permitting these possibilities:
let owned: String;
let borrowed: &str;
let owned_ref: &String;
let map: HashMap<String, i32>;
map.entry2(owned);
map.entry2(borrowed);
map.entry2(owned_ref);
let map: HashMap<&str, i32>;
map.entry2(borrowed);
map.entry2(owned_ref);
Edit: In particular, I think it's going to be an issue that String
does not implement Borrow<&'a str>
(which totally makes sense). We might need higher-ranked lifetimes for this?