Skip to content

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

@xrl

Description

@xrl

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 )
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions