I'm trying to remove duplicates in the below example:
struct User {
reference: String,
email: String,
}
fn main() {
let mut users: Vec<User> = Vec::new();
users.push(User {
reference: "abc".into(),
email: "[email protected]".into(),
});
users.push(User {
reference: "def".into(),
email: "[email protected]".into(),
});
users.push(User {
reference: "ghi".into(),
email: "[email protected]".into(),
});
users.sort_by(|a, b| a.email.cmp(&b.email));
users.dedup();
}
I'm getting the error
error[E0599]: no method named `dedup` found for type `std::vec::Vec<User>` in the current scope
--> src/main.rs:23:11
|
23 | users.dedup();
| ^^^^^
|
How can I remove duplicates from users
by email
values? Can I implement the dedup()
function for struct User
or do I have to do something else?