假设我有以下示例:
struct Client {
email: String,
phone: String,
details: String
}
fn main() {
let mut clients: Vec<Client> = Vec::new();
clients.push(Client {
email: "john@gmail.com".to_string(),
phone: "0123456789".to_string(),
details: "custom details".to_string(),
});
clients.push(Client {
email: "john@gmail.com".to_string(),
phone: "0123456789".to_string(),
details: "other details".to_string(),
});
clients.push(Client {
email: "james@gmail.com".to_string(),
phone: "9876543210".to_string(),
details: "test".to_string(),
});
}
什么是在这个向量中通过检查
email
和phone
在Client
中计算部分重复项的最佳(Rust习惯用语)方法?例如,在上面的例子中将找到一个重复项。
.map()
函数将电子邮件和电话提取为一个元组。然后,问题就变成了计算完全重复的数量。 - kennytm