So I decided to see if I could make my own implementation of std::collections:BTreeMap, so I could efficiently modify keys while iterating. It is here:
For iteration I have implemented walk and walk_mut which take a closure ( and a start key ). This does what I need for now. However I don't see how to efficiently implement Rust iteration, at least not with map mutation, in safe Rust. For the iterator State I would need a list (stack) of mutable references, and I don't think the borrow checker will allow it ( I am not 100% sure... maybe I could try it and see! ). I suppose I could keep position in the form of the index at each level, which isn't too bad I suppose. Or I could store the whole map in two Vecs, one for leaf nodes, one for non-leaf nodes, in other words an index approach.
Are the above thoughts correct? It seems like there is no "clean" way to implement BTreeMap efficiently (and naturally) in safe Rust. Am I missing anything?
[ I guess I could use Rc/Refcell, but then my map will no longer be Sync+Send ]
Oh, I did refer to this, although I don't understand it all, but it describes an "unsafe" approach: Rust Collections Case Study: BTreeMap