I currently have the following code:
let mut create_new_heap_entry = || {
//filtered version of the actual function to keep it simple
//directed_edge_info is moved here
let edge_info = create_edge_information(directed_edge_info);
//not very relevant for this question
let ret = Rc::new(HeapEntry::new(edge_info));
data.heap.push(Rc::clone(&ret));
ret
};
//data.distance is of type HashMap<i32, Rc<HeapEntry>>
data.distances.entry(adj_node).and_modify(|e| {
if some_condition {
*e = create_new_heap_entry();
}
}).or_insert_with(create_new_heap_entry);
This gives the following error: closure cannot be moved more than once as it is not Copy due to moving the variable directed_edge_info out of its environment
But if you think about it and_modify will never run together with or_insert so this isn't actually a problem, but I understand that rust only cares about function signatures and doesn't worry about the actual implementations of those functions.
My question is if there is a function of HashMap tha solves this issue ? Or how would I rewrite the map update to solve this?