If I were to pass a mutable reference to an element in a vector type, the moment that someone else removes an element from the vector, the entire thing is shifted downwards. This would invalidate a mutable reference, causing a dangling reference, correct? (supposing the element removed has an index less than the index of the element which has an active mutable borrow)
If so, then would a hashmap alleviate this problem? I need to pass out mutable references to downstream consumers (the program has to use some unsafe to convert an unbounded lifetime to a bounded lifetime in order to pass the borrow checks), and the logic of the code gaurantees that at most one mutable reference for a specific element exists at a time. However, my biggest concern is that by passing a mutable reference from a vector/hashmap type, the referrent's position may change during item removal and thus the reference becomes dangling.