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

Provide Vec::dedup_by in addition to Vec::dedup #1301

Closed
xrl opened this issue Sep 30, 2015 · 1 comment
Closed

Provide Vec::dedup_by in addition to Vec::dedup #1301

xrl opened this issue Sep 30, 2015 · 1 comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.

Comments

@xrl
Copy link

xrl commented Sep 30, 2015

I would like to dedup a Vec of structs using a property of the struct. I do not want to map since I want to maintain the contents of the Vec. The stdlib Vec can sort_by using a comparator F: FnMut(&T, &T) -- it would be consistent for Vec to dedup_by using the same kind of comparator.

My contrived example:

#[derive(PartialEq)]
struct CoolThing( pub &'static str, pub u8 );

fn main(){
    let mut things = vec![
      CoolThing("Jimbo", 10), CoolThing("Billy", 10)
    ];

    let uniq_things = things.dedup_by(|x| x.1);
    assert!( vec![CoolThing("Billy",10)] == uniq_things )
}
@nrc nrc added the T-libs-api Relevant to the library API team, which will review and decide on the RFC. label Aug 22, 2016
@mbrubeck
Copy link
Contributor

Fixed by rust-lang/rust#36743.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

3 participants