Mutable Checklist Iterator

I would like to accomplish something along those lines:

let todo_list = // fill with items

while let Some(next_item) = todo_list.pop() {
    // work on task

    // here comes the tricky part
    let some_subtask = // identify related task
    if let Some(subtask) = todo_list.remove(some_subtask) {
        // work on the subtask
        // this one does not spawn subtasks
    } 
}

In my case the tasks are identified by an index type with some random value in it. Therefore I tried a few things with HashSet but those didn’t seem to work too well. I am still too unfamiliar with the borrow checker to write acceptable code in this case.

I am sorry, but I am having some trouble finding the problem. Look at this playground, as you can see it compiles flawlessly. Obviously, it has a lot of design problem this example, maybe your problem is related to a more sophisticated implementation.

Give me some feedback, maybe I am able to help you with the actual problem.

Oh thanks, you are right! It looks like I got really confused at some point and I can’t even reconstruct the problem anymore… Your example really helped me :slight_smile:

1 Like