我有两个 FnvHashMap,首先声明如下: FnvHashMap<(i32, i32), Employee> 第二个:FnvHashMap<(i32, i32), Employee> Employee 在哪里
pub struct Employee {
pub emp_id: i32,
pub lang_id: i32,
pub dept_id: f64,
pub description: String,
}
我需要遍历“第一”FnvHashMap 并查看“第二”FnvHashMap 中是否有匹配的记录(emp_id 和 lang_id)
我可能不需要考虑 dept_id 和描述
提前致谢。
实现嵌套循环后的新代码
for (_, employee1) in &first {
for (_, employee2) in &second {
if employee1.emp_id == employee2.emp_id && employee1.lang_id == employee2.lang_id {
values.push(OldNew {
old: employee2,
new: employee1,
});
}
}
}
let new = first
.into_iter()
.filter(|(a, _)| !old.contains_key(a))
.map(|(_, a)| a)
.collect();
let deleted = second
.iter()
.filter(|(a, _)| !new.contains_key(a))
.map(|(&a, _)| a)
.collect();
Changes {
deleted,
new,
values,
}
pub struct Changes<T, I> {
pub deleted: Vec<I>,
pub new: Vec<T>,
pub values: Vec<OldNew<T>>,
}
expected struct `organization::models::employee_stat::Employee`, found `&organization::models::employee_stat::Employee`