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

Add HashMap::get_pair? #27237

Closed
SimonSapin opened this issue Jul 23, 2015 · 2 comments
Closed

Add HashMap::get_pair? #27237

SimonSapin opened this issue Jul 23, 2015 · 2 comments

Comments

@SimonSapin
Copy link
Contributor

HashMap has this method:

    pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V>
        where K: Borrow<Q>, Q: Hash + Eq
    {
        self.search(k).map(|bucket| bucket.into_refs().1)
    }

I’d like to add this one, where the only difference is removing .1:

    pub fn get_pair<Q: ?Sized>(&self, k: &Q) -> Option<(&K, &V)>
        where K: Borrow<Q>, Q: Hash + Eq
    {
        self.search(k).map(|bucket| bucket.into_refs())
    }

This can be useful when K is &'a T where 'a is a longer lifetime than in Q.

Is this too obscure to pull its weight in std?

CC @gankro

@apasel422
Copy link
Contributor

This is rust-lang/rfcs#1194.

@SimonSapin
Copy link
Contributor Author

Indeed, thanks!

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

2 participants