我是 Rust 新手,这是我遍历两个 FnvHashMap 并找到差异的代码
impl SaveChanges for Employee{
type Item = Employee;
type List = FnvHashMap<(i32, i32), Employee>;
type Id = (i32, i32);
fn find_changes(
old: &FnvHashMap<(i32, i32), Employee>,
new: FnvHashMap<(i32, i32), Employee>,
) -> Changes<Employee, (i32, i32)> {
let deleted = second
.iter()
.filter(|(a, _)| !new.contains_key(a))
.map(|(&a, _)| a)
.collect();
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();
Changes {
deleted,
new,
values,
}
}
pub struct Changes<T, I> {
pub deleted: Vec<I>,
pub new: Vec<T>,
pub values: Vec<OldNew<T>>,
}
当我将这些值添加到另一个向量时,Rust 抛出编译错误
values,
expected struct `organization::models::employee_stat::Employee`, found `&organization::models::employee_stat::Employee`
任何帮助将非常感激。谢谢