3
我試圖刪除下面的例子重複刪除重複:來自自定義結構的載體
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();
}
我得到的(預期的)錯誤
src/main.rs:14:8: 14:15 error: no method named `dedup` found for type `collections::vec::Vec<User>` in the current scope
src/main.rs:14 users.dedup();
^~~~~~~
error: aborting due to previous error
我怎樣才能刪除重複從users
由email
值?我可以爲struct User
實施dedup()
功能還是必須執行其他操作?