Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

entry2 documentation makes incorrect claim #2

Open
apasel422 opened this issue Nov 22, 2015 · 1 comment
Open

entry2 documentation makes incorrect claim #2

apasel422 opened this issue Nov 22, 2015 · 1 comment

Comments

@apasel422
Copy link

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.

@apasel422
Copy link
Author

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant