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

Adding Extend<&'a (K, V)> for HashMap<K, V, S, A> #340

Merged
merged 2 commits into from Jun 9, 2022

Conversation

JustForFun88
Copy link
Contributor

I think that it is strange that we can do something like this:

fn main() {
    use hashbrown::HashMap;
    let mut map = HashMap::new();
    let some_vec: Vec<_> = vec![(1, 1), (2, 2), (3, 3), (4, 4)];
    map.extend(some_vec.iter().map(|&(k, v)| (k, v)));
}

but cannot do something like this:

fn main() {
    use hashbrown::HashMap;
    let mut map = HashMap::new();
    let some_vec: Vec<_> = vec![(1, 1), (2, 2), (3, 3), (4, 4)];
    map.extend(some_vec.iter()); // Or map.extend(&some_vec);
}

In any case, it can work only if K and V are Copy, and also inside Extend<(K, V)> we use HashMap::insert, not HashMap::insert_unique_unchecked, so adding Extend<&'a (K, V)> should be Ok.

@Amanieu
Copy link
Member

Amanieu commented Jun 9, 2022

@bors r+

@bors
Copy link
Collaborator

bors commented Jun 9, 2022

📌 Commit bedc992 has been approved by Amanieu

@bors
Copy link
Collaborator

bors commented Jun 9, 2022

⌛ Testing commit bedc992 with merge 620cfc0...

@bors
Copy link
Collaborator

bors commented Jun 9, 2022

☀️ Test successful - checks-actions
Approved by: Amanieu
Pushing 620cfc0 to master...

@bors bors merged commit 620cfc0 into rust-lang:master Jun 9, 2022
@JustForFun88 JustForFun88 deleted the add_new_extend branch June 9, 2022 14:49
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

Successfully merging this pull request may close these issues.

None yet

3 participants