I have a HashMap with key = id, value = Status; Now I want to update the status, but I have to remove and insert, because the new status is created from the old status. Is there any way to update without remove and insert?
enum Status {
InCompleted(HashSet<WorkerId>),
Working(WorkerId, HashSet<WorkerId>),
Completed,
}
impl Status {
fn to_working(self, worker_id: WorkerId) -> Self {
match self {
Self::InCompleted(w) => Self::Working(worker_id, w),
_ => self,
}
}
// remove and insert new
let old_status = h.remove(&id).unwrap();
h.insert(id, old_status.to_working(cur_worker));